一、效果(监听页面滚动使得超过屏幕的数字每次出现都有数字滚动效果)

二、代码

在滚动数字的标签上加上类名counter

<div class="about_right flex5"><div class="found flex6" aos="fade-up" aos-delay="300"><p class="counter">2004</p><span>公司成立(年)</span></div><div class="found flex6" aos="fade-up" aos-delay="300"><p><span class="counter">100</span><label>+</label></p><span>员工人数(人)</span></div><div class="found flex6" aos="fade-up" aos-delay="300"><p class="counter">1.6</p><span>总投资(亿元)</span></div>
</div>

引入js(js在下边,复制就行,jquery文件自己引入吧),写入jQuery

<script src="./js/jquery-3.2.1.min.js"></script>
<script src="./js/numRoll/jquery.waypoints.min.js"></script>
<script src="./js/numRoll/jquery.counterup.min.js"></script>
<script type="text/javascript">// 数字滚动$(function () {$('.counter').counterUp({delay: 20,//每个数字动画的延迟时间,单位毫秒。time: 2000//计数动画总的持续时间。});})
</script>

css样式

.about_right {width: calc(100% - 9.5rem);height: 100%;background: url('../../img/index/about_bg2.png') no-repeat center / 100% 100%;padding: 0 1.725rem;display: flex;justify-content: space-between;align-items: center;
}
.about_right .found {width: calc(100% / 3);height: 1.875rem;padding: 0 0.125rem;display: flex;flex-direction: column;justify-content: flex-start;align-items: center;
}
.about_right .found p {font-size: 1rem;font-weight: bold;color: #fff;display: flex;align-items: flex-start;
}
.about_right .found p span {font-size: 1rem;font-weight: bold;
}
.about_right .found p label {font-size: 0.3rem;
}
.about_right .found span {font-size: 0.25rem;color: #fff;word-break: break-all;text-align: center;
}

jquery.counterup.min.js

(function(t) {"use strict";t.fn.counterUp = function (e) {var a = t.extend({time: 400,delay: 10}, e);return this.each(function () {var e = t(this),n = a,u = function () {e.data("counterupTo") || e.data("counterupTo", e.text());var t = parseInt(e.data("counter-time")) > 0 ? parseInt(e.data("counter-time")) : n.time,a = parseInt(e.data("counter-delay")) > 0 ? parseInt(e.data("counter-delay")) : n.delay,u = t / a,r = e.data("counterupTo"),o = [r],c = /[0-9]+,[0-9]+/.test(r);r = r.replace(/,/g, "");for (var d = (/^[0-9]+$/.test(r), /^[0-9]+\.[0-9]+$/.test(r)), s = d ? (r.split(".")[1] || []).length : 0, i = u; i >= 1; i--) {var p = parseInt(Math.round(r / u * i));if (d && (p = parseFloat(r / u * i).toFixed(s)), c)for (;/(\d+)(\d{3})/.test(p.toString());) p = p.toString().replace(/(\d+)(\d{3})/, "$1,$2");o.unshift(p)}e.data("counterup-nums", o), e.text("0");var f = function () {e.text(e.data("counterup-nums").shift()), e.data("counterup-nums").length ? setTimeout(e.data("counterup-func"), a) : (delete e.data("counterup-nums"), e.data("counterup-nums", null), e.data("counterup-func", null))};e.data("counterup-func", f), setTimeout(e.data("counterup-func"), a)};e.waypoint(u, {offset: "100%",triggerOnce: !0})})}
})(jQuery);

jquery.waypoints.min.js

!function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){(!e.didScroll||n.isTouch)&&(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll<a.triggerPoint,h=o.newScroll>=a.triggerPoint,p=l&&h,u=!l&&!h;(p||u)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var c in t)t[c].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,u,c,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w<s.oldScroll,p=d.triggerPoint>=s.oldScroll,u=h&&p,c=!h&&!p,!g&&u?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&c?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}();

js、jQuery实现数字滚动效果相关推荐

  1. jquery实现数字滚动效果

    因为需要,自己用jquery动手写了数字滚动效果 实现原理 1.先确定数字最大的位数,比如说最大数为6位数,就画出一排6个高度为30px的方格; 2.然后在每个方格区域增加一竖排的 012345678 ...

  2. jQuery数字滚动效果

    jQuery数字滚动效果## 引入jQuery <script src="js/jquery.min.js"></script> body <div ...

  3. CSS3 + JS 数字滚动效果

    原生JS+CSS3版: <!DOCTYPE html> <html> <head><title>CSS3 数字滚动效果</title> &l ...

  4. vue做数字滚动效果

    vue实现数字滚动效果 近期在做项目的时候,产品要求实现数字滚动效果如下: 用jquery实现 html: <div class="develop"> <!--滚 ...

  5. html数字自动滚动代码怎么写,你可能需要这样的大屏数字滚动效果

    大屏数字滚动效果来源于最近工作中一张大屏的UI图,该UI图上有一个模块需要有数字往上翻动的效果,以下是最终实现的效果: 思路 在实现此效果之前,我们先来捋一下思路,用思维导图来设计一下我们的实现步骤, ...

  6. 【网站】数字滚动效果的实现方法

    代码如下: HTML部分: <div class="box Counter"><ul class="clearfix"><li&g ...

  7. html横向滚动字幕代码,jQuery文字横向滚动效果的实现代码

    很多网站都有公告,并且都喜欢用横向滚动的方式来展现.最近自己用jQuery也写了文字横向滚动,实现了自定义滚动速度,鼠标经过时暂停的功能. HTML代码如下: jQuery文字横向滚动jQuery制作 ...

  8. 初级开发者福音:手把手教你实现数字滚动效果~

    文章目录 一.前言 二.背景知识 三.实现方案 Step 1:分析需求 Step 2:实现单个数字的滚动效果 Step 3:组件接口设计 Step 4:完善组件 一.前言 前端数字滚动显示的场景很多, ...

  9. JS 自定义实现数字滚动处理

    一.浏览器端js自定义实现数字滚动 使用示例: <!DOCTYPE html> <html lang="en"><head><meta c ...

最新文章

  1. 自动驾驶第一案结果敲定,谷歌无人驾驶和Uber达成2.5亿美元和解协议
  2. golang 返回值报错 cannot use nil as type string in return argument
  3. PHP网站安装程序的原理及代码
  4. python随机数种子通俗_随机数种子random.seed()理解
  5. sublime text2快捷键
  6. 计算机密码忘了 开不了机怎么办,电脑设了开机密码现在忘了开不了机怎么处理?...
  7. python操作hive表_python处理数据,存进hive表的方法
  8. 银行计算机储蓄系统程序流程图,银行储蓄系统流程图
  9. 如何将 MacBook 的外置屏幕设置为主屏幕
  10. 线上编程学院codecademy
  11. 小技巧——网页下载提速
  12. UVM RAL 中的显示预测 uvm_reg_predictor
  13. 【济南校区】将来的你,一定会感谢现在拼命的自己
  14. 如何启用计算机网络,启用网络发现,教您win10怎么启用网络发现
  15. c语言判断字符是否为某字母,判断字符是否为字母
  16. Triggers — 触发响应
  17. 用 ListBox 和 DataBinding 显示列表数据 (木野狐译)
  18. win11蓝牙无法连接怎么办?win11蓝牙无法连接的解决方法
  19. TCP的CLOSE_WAIT和TIME_WAIT问题汇总
  20. 【Oracle】SQL字符串查找_精确查询,只要23不要234

热门文章

  1. Unknown command: crawl(爬虫框架Scrapy遇到的常见错误)
  2. passive模式 tcp_ftp的主动模式active mode和被动模式 passive mode的配置和区
  3. 中国牛人自制直升机,视频!仅花2万RMB!
  4. printf用法大全,C语言printf格式控制符一览表printf用法大全,C语言printf格式控制符一览表
  5. 利用JAVA解决鸡兔同笼的问题
  6. 常见网络端口 和 常见网络协议
  7. ToolTips Notifications
  8. 求一个集合的所有子集问题
  9. 鸿蒙系统网络连接设置ip,修改本地连接的TCP/IP属性设置
  10. ubuntu 系统时间