How to jump to top of browser page
I'm writing a modal popup and I need the browser to jump to the top of the screen when the open modal button is pressed. Is there a way to scroll the browser to the top using jQuery?
You can set the scrollTop
, like this:
$('html,body').scrollTop(0);
Or if you want a little animation instead of a snap to the top:
$('html, body').animate({ scrollTop: 0 }, 'fast');
Without animation, you can use plain JS:
scroll(0,0)
With animation, check Nick's answer.
If you're using jQuery UI dialog, you could just style the modal to appear with the position fixed in the window so it doesn't pop-up out of view, negating the need to scroll. Otherwise,
var scrollTop = function() {
window.scrollTo(0, 0);
};
should do the trick.
链接地址: http://www.djcxy.com/p/89048.html上一篇: 将旧的.html页面重定向到没有HTML扩展页面的新页面?
下一篇: 如何跳到浏览器页面的顶部