How to jump to top of browser page

2019-01-29 17:57发布

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?

7条回答
对你真心纯属浪费
2楼-- · 2019-01-29 18:26

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.

查看更多
登录 后发表回答