当滚动条滚动到页面某个位置时,触发js,
$(window).scroll(function (){ //window.onload = function() { // setup CountUp object demo = new CountUp('myTargetElement', 0, 30, 0, 2, options); demo1 = new CountUp('yingyong', 0, 100, 0, 2, options); demo2 = new CountUp('qiye', 0, 20000, 0, 2, options); demo.start(); demo1.start(); demo2.start(); //document.getElementById('version').innerHTML = 'v'+demo.version(); }); $(window).scroll(function (){ if ($(window).scrollTop()>200) { //code........ } });
两个例子