开发者

JQuery scrollTop() not doing anything

My .scrollTop() is just not working. It's used in a function (which do get called - checked with an alert) but nothing happens.

I tried:

$(window).scrollTop();
$("html").scrollTop();
$(document).scrollTop();开发者_JAVA百科

I tried them separately and together, and it just doesn't do anything.

All I need to do is let my page scroll to the top. Any tips and tricks?


You need $("html, body").scrollTop(0); that is a cross-browser solution to scroll to the vertical position 0 (to the top).

The way you are doing scrollTop() does nothing because its a getter that returns the current vertical position.


scrollTop() gets the current scroll top of an element but doesn't set it, try the jQuery ScrollTo plugin, it has the functionality you need.


$("body").scrollTop(); would work just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜