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?
Advertisement
Answer
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');