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?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
You could do it without javascript and simply use anchor tags? Then it would be accessible to those js free.
although as you are using modals, I assume you don't care about being js free. ;)
I know this is old, but for those having problems in Edge:
Plain JS:
window.scrollTop=0;
Unfortunately,
scroll()
andscrollTo()
throw errors in Edge.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. Other
Without animation, you can use plain JS:
With animation, check Nick's answer.
You can set the
scrollTop
, like this:Or if you want a little animation instead of a snap to the top: