jQuery-没有动画的ScrollTop [英] jQuery - ScrollTop without animation
本文介绍了jQuery-没有动画的ScrollTop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在没有动画的情况下使用滚动条
How can I use the scrolltop without an animation
此代码有效:
var offTop = $('#box').offset().top;
offTop = offTop-43;
$('#mainCt').animate({scrollTop: '+=' + offTop + 'px'}, 400);
这是我的(无效的解决方案):
And here are my (not working solutions):
$("#mainCt").scrollTop('+=' + offTop + 'px'); // doesn't work
$("#mainCt").scrollTop('+='+offTop); // doesn't work
hhh = setTimeout(' $("#mainCt").scrollTop('+offTop+');',800); // doesn't work
演示
http://jsfiddle.net/DNNFF/9/
推荐答案
也许,如果您不想要动画或任何奇特的东西,只需使用锚点即可
maybe if you don't want an animation or anything fancy just use an anchor
<a name="top"></a>
将其放置在需要滚动的位置
Place it where you need to scroll
以及您要在其中调用use的函数中
and in your function where you are calling use
document.location.href="#top";
您还可以创建一个函数,将锚点附加到元素之前,执行document.location
的操作,然后再删除该锚点.
You could also create a function to append the anchor before the element, do the document.location
thing and later remove that anchor.
这篇关于jQuery-没有动画的ScrollTop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文