简体   繁体   English

.animate(); 在Javascript中冻结了一秒钟

[英].animate(); in Javascript is Freezing for a second

I am having problems with .animate() in Javascript. 我在Javascript中遇到.animate()问题。 I am using it to automatically scroll to an element in a div whitch is working. 我正在使用它来自动滚动到div鞭子正在工作的元素。 The problem I have is that after a few milliseconds the scrolling freezes for a second or so and then continues at that point where it should already had animated to and then it continues animating without any problems. 我遇到的问题是,几毫秒后,滚动会冻结一秒钟左右,然后在应该已经动画化的位置继续滚动,然后继续进行动画处理而不会出现任何问题。

The scrollable div contains about 36 divs with the width of 75 px and in the background is a dynamically generated SVG graph. 可滚动的div包含约36个div,宽度为75 px,在后台是动态生成的SVG图。 To animate the div I using 为我使用的div设置动画

parent.stop(true, false).animate({
            scrollLeft: offsetToLeft
        }, 50*Math.abs(elementsToSkipp), function (element, index) {
            //Show highlight the element and refresh data
            return false;
        }.bind(this, forecastElement[0], index));

The return false; return false; and .stop(true, false) is from Stackoverflow, but it did not really fixed my issue. .stop(true, false)来自Stackoverflow,但它并没有真正解决我的问题。 Help is very appreciated. 非常感谢您的帮助。

EDIT: I only experience this lag on mobile devices (iOS, Android), there is no such lag on a Desktop PC. 编辑:我只在移动设备(iOS,Android)上遇到这种滞后,而在台式机上则没有这种滞后。

Thanks, 谢谢,

David 大卫

it sounds like you are running your animation as a response to a scroll event . 听起来好像您正在运行动画以响应滚动事件 here is a post wich solves this kind of problem (including code): Jquery slow reaction time 这是解决此类问题(包括代码)的文章: jQuery响应时间慢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM