使用animate-scrollTo时,jQuery闪烁 [英] jQuery flicker when using animate-scrollTo
本文介绍了使用animate-scrollTo时,jQuery闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于 scrollTo
函数,当它被一个jQuery animate
函数调用时,我遇到了一个问题。
I have a problem with the scrollTo
function when it is called by a jQuery animate
function.
这里我的代码:
$("#button").click(function(){
$("body").animate({scrollTop: 1400},"slow");
});
当我点击按钮,闪烁出现在身体滚动之前。例如,我在(滚动位置)1000,当我点击按钮时,发生以下情况:
When I click the button, the flicker appears before the body scrolling. For example, I'm on (scroll position) 1000, and when I clicked the button the following happened:
- 滚动位置)1400出现,它看起来像我已经走
到(位置)1400 - 然后它再次移动到(位置)1000,这发生得这么快
,看起来像一个闪烁 - 最后它像正常的滚动一样滚动到1400.
在firefox它总是出现,有时在chrome也。
On firefox it always appears, and sometimes on chrome also.
推荐答案
我有同样的闪烁问题。它是由触发函数的链接中的哈希锚引起的。修复它与preventDefault():
I had the same flickering problem. It was caused by the hash anchor in the link that triggers the function. Fixed it with preventDefault():
$("#button").click(function(e){
e.preventDefault();
$("body").animate({scrollTop: 1400},"slow");
});
这篇关于使用animate-scrollTo时,jQuery闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文