Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

javascript - 如何跳转到浏览器页面的顶部(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?(有没有办法使用jQuery将浏览器滚动到顶部?)   ask by Exitos translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can set the scrollTop , like this:(您可以设置scrollTop ,如下所示:)

$('html,body').scrollTop(0); Or if you want a little animation instead of a snap to the top:(或者,如果你想要一个小动画而不是一个快照到顶部:) $('html, body').animate({ scrollTop: 0 }, 'fast');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...