jQuery+css3碎片化文字loading加载动画特效

来源:https://www.sucaihuo.com/js/4438.html 2019-06-17 11:29浏览(807) 收藏

jQuery+css3 transform属性制作的碎片化文字loading加载动画特效,文字打散组合不断循环的动画效果。
jQuery+css3碎片化文字loading加载动画特效
分类:文字特效 > 文字动画 难易:初级
查看演示 下载资源 下载积分: 20 积分

js代码

<script src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    let loading = $('.loading').wrapInner('<div></div>'),
        min = 20,
        max = 70,
        minMove = 10,
        maxMove = 20;

    startAnimation(loading);

    loading.on('animationend webkitAnimationEnd oAnimationEnd', 'span:last-child', e => {
        startAnimation(loading);
    });

    //设置CSS变量并根据需要生成跨距
    function setCSSVars(elem, min, max, minMove, maxMove) {
        let width = Math.ceil(elem.width()),
            text = elem.text();
        for(let i = 1; i < width; i++) {
            let num = Math.floor(Math.random() * (max - min + 1)) + min,
                numMove = Math.floor(Math.random() * (maxMove - minMove + 1)) + minMove,
                dir = (i % 2 == 0) ? 1 : -1,
                spanCurrent = elem.find('span:eq(' + i + ')'),
                span = spanCurrent.length ? spanCurrent : $('<span />');
            span.css({
                '--x': i - 1 + 'px',
                '--move-y': num * dir + 'px',
                '--move-y-s': ((i % 2 == 0) ? num * dir - numMove : num * dir + numMove) + 'px',
                '--delay': i * 10 + 'ms'
            });
            if(!spanCurrent.length) {
                elem.append(span.text(text));
            }
        }
    }

    //开始动画
    function startAnimation(elem) {
        elem.removeClass('start');
        setCSSVars(elem, min, max, minMove, maxMove);
        void elem[0].offsetWidth;
        elem.addClass('start');
    }
    
});
</script>
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2