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

jquery实现的iPad翻页翻书动画特效

一款翻书动画效果,鼠标单击即可触发翻页动画,iPad支持左/右滑动的简单翻页效果。
  动画效果
 817  0

jquery轻量级动画打字特效的web终端模拟器

一个轻量级的基于web的终端模拟器,用于模拟网页上的shell(命令行)环境。
  动画效果
 6187  0

基于GSAP创建的鼠标悬停动画特效插件

一个奇特的弹性悬停效果,带有交互式光标和波纹点击动画,将鼠标转变成圆形小球,鼠标悬停在按钮上时,变成放大镜。
  动画效果
 3247  0

led在线时钟文字展示特效脚本

一款在线时钟动画特效,模拟LED屏幕效果,动态的展示当前时间。
  动画效果
 2297  0

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

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