jquery自定义的滚动条下拉触发数字动画特效代码

所属分类: 网页特效-动画效果    2023-11-05 03:32:32

jquery自定义的滚动条下拉触发数字动画特效代码 ie兼容6
反馈问题  查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery自定义的滚动条下拉触发数字动画特效代码(共3个文件)

    • index.html
    • multi-animated-counter.js
    • style.css

使用方法

$(function () {

    // ! Counter (used for Social Proof)

    /* Usage example
        <div id="counters_1">
            <div ="counter" data-TargetNum="10" data-Speed="6000"></div>
            <div class="counter" data-TargetNum="7" data-Speed="7000" 
            data-Direction="reverse" data-Easing="linear"></div>
            <div class="counter" data-TargetNum="80333" data-Speed="2500">0</div>
        </div>
        <div id="counters_2">
            <div class="counter" data-TargetNum="4200" data-Speed="1000">0</div>
            <div class="counter" data-TargetNum="4500" data-Speed="4000">0</div>
            <div class="counter" data-TargetNum="4743">0</div>
        </div>
        <div id="counters_3">
            <div class="counter" data-TargetNum="5200" data-Speed="1000">0</div>
            <div class="counter" data-TargetNum="5500" data-Speed="4000">0</div>
            <div class="counter" data-TargetNum="5743">0</div>
        </div>
    
       Required attr: data-TargetNum
       Optionals attr: data-Speed(milisecons), data-Direction(reverse), data-Easing(linear, swing)

       **CONFIG**
       Please set a the ID's to watch, a class for all counters and a default speed

       Avoid to use this script in pages where it isn't needed
    */

    // CONFIG
    let visibilityIds = ['#counters_1', '#counters_2', '#counters_3']; //must be an array, could have only one element
    let counterClass = '.counter';
    let defaultSpeed = 3000; //default value

    // END CONFIG

    //init if it becomes visible by scrolling
    $(window).on('scroll', function () {
        getVisibilityStatus();
    });

    //init if it's visible by page loading
    getVisibilityStatus();

    function getVisibilityStatus() {
        elValFromTop = [];
        var windowHeight = $(window).height(),
            windowScrollValFromTop = $(this).scrollTop();

        visibilityIds.forEach(function (item, index) { //Call each class
            try { //avoid error if class not exist
                elValFromTop[index] = Math.ceil($(item).offset().top);
            } catch (err) {
                return;
            }
            // if the sum of the window height and scroll distance from the top is greater than the target element's distance from the top, 
            //it should be in view and the event should fire, otherwise reverse any previously applied methods
            if ((windowHeight + windowScrollValFromTop) > elValFromTop[index]) {
                counter_init(item);
            }
        });
    }

    function counter_init(groupId) {
        let num, speed, direction, index = 0;
        $(counterClass).each(function () {
            num = $(this).attr('data-TargetNum');
            speed = $(this).attr('data-Speed');
            direction = $(this).attr('data-Direction');
            easing = $(this).attr('data-Easing');
            if (speed == undefined) speed = defaultSpeed;
            $(this).addClass('c_' + index); //add a class to recognize each counter
            doCount(num, index, speed, groupId, direction, easing);
            index++;
        });
    }

    function doCount(num, index, speed, groupClass, direction, easing) {
        let className = groupClass + ' ' + counterClass + '.' + 'c_' + index;
        if(easing == undefined) easing = "swing";
        $(className).animate({
            num
        }, {
            duration: +speed,
            easing: easing,
            step: function (now) {
                if (direction == 'reverse') {
                    $(this).text(num - Math.floor(now));
                } else {
                    $(this).text(Math.floor(now));
                }
            },
            complete: doCount
        });
    }
})

站长提示:
1. 平台上所有素材资源,需注册登录会员方能正常下载。
2. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励20K币
3. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
4. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 动画效果

js+css卡片水平翻转动画特效

一款卡片翻转动画代码,3D水平自动翻转,很震撼!
  动画效果
 218  

HTML5熊熊火焰文字动画特效

一款纯js创建的火焰文字效果,可自定义设置火焰参数、字体大小、火焰动画高度等。
  动画效果
 112  

15种CSS实现的鼠标悬停动画特效

15种不同的纯CSS悬停效果,包括翻转、开门动画、展开、波浪、旋转动画,按钮的背景颜色和大小可根据自己的需求自定义设置。
  动画效果
 269  

JavaScript实现的像素小方块图片背景动画特效代码

JavaScript代码创建的一个动态的像素背景动画。该代码生成一个随着时间推移而移动和衰减的正方形网格。可通过鼠标点击、生成新的方块或重置现有方块进行交互。
  动画效果
 163  

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论