Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何优化我的数字动画javascript代码?_Javascript_Jquery_Html - Fatal编程技术网

如何优化我的数字动画javascript代码?

如何优化我的数字动画javascript代码?,javascript,jquery,html,Javascript,Jquery,Html,这是我的代码: const ratingcount=document.queryselectoral('.ratingcount'); const totalratingcounter=ratingcount.length; var stopNow=总计计数器 countEach() $(窗口).on('scroll',函数(e){ countEach() }) 函数countEach(){ $('.ratingcount')。每个(函数(){ if(showOnScreen(this)&&&

这是我的代码:

const ratingcount=document.queryselectoral('.ratingcount');
const totalratingcounter=ratingcount.length;
var stopNow=总计计数器
countEach()
$(窗口).on('scroll',函数(e){
countEach()
})
函数countEach(){
$('.ratingcount')。每个(函数(){
if(showOnScreen(this)&&&$(this).attr('show')!='false'&&stopNow!=0){
//console.log($(this.text())
//console.log($(this.attr('show'))
$(this.attr('show','false'))
号码(本)
stopNow=stopNow-1;
}/*如果(!屏幕上显示(此)){
$(this.attr('show','true'))
}*/
})
}
屏幕上的功能显示(目标){
如果($(窗口).scrollTop()+$(窗口).height()>=$(目标).offset().top)
返回true;
其他的
返回false;
}
函数编号RANIMATE(目标){
变量$this=$(目标);
jQuery({
柜台:0
}).制作动画({
计数器:$this.text()
}, {
持续时间:1000,
放松:"摇摆",,
步骤:函数(){
$this.text(this.Counter.toFixed(1));
}
});
}

7.8

































7.8
脚本将运行或不运行,对于所使用的internet连接,脚本的功能应该没有任何影响。您的脚本是否等待DOM加载后执行?我不是Javascript专家,我花了很多时间制作@TimothyGroote。我不知道,你是什么意思,对不起。@11维有时候,脚本会停在一个随机数上。(比如2.3,而原来的数字是8.6)你的代码片段在互联网速度慢的时候工作得很好——我使用了Chrome的网络调试面板和模拟GPRS环境,它工作得很好。