重新加载浏览器不会将页面重置为顶部 [英] Reload browser does not reset page to top
问题描述
我以为当您单击刷新时,浏览器应该将您的页面重置到顶部?我正在使用 js
手风琴,当我刷新时,它会关闭手风琴但不会将页面重新定位到顶部.
I thought when you clicked refresh, that the browser was supposed to reset your page to the top? I am using a js
accordion and when I refresh, it closes the accordion but does not reposition the page to the top.
http://imip.rvadv.com/index3.html
推荐答案
好吧,正如你所见,它没有 :)
Well, as you can see, it does not :)
但是你可以用一些简单的 jQuery 来强制它:
But you can force it with some simple jQuery:
$(document).ready(function(){
$(this).scrollTop(0);
});
似乎适用于 IE 9、FF 12 和 Chrome 20.0 的唯一方法如下:
The only way that seems to work in IE 9, FF 12 and Chrome 20.0 is the following:
$(document).ready(function(){
$('html').animate({scrollTop:0}, 1);
$('body').animate({scrollTop:0}, 1);
});
奇怪的是,当我尝试直接滚动元素而不应用任何动画(即 $('html').scrollTop(0)
)时,它不起作用.由于持续时间设置为 1 毫秒,因此用户不会注意到任何事情.
Strange thing is that when I tried scrolling the elements directly without applying any animation (that is, $('html').scrollTop(0)
), it didn't work. Since the duration is set to 1 millisecond, the user will not notice anything.
如果有人能对此有所了解,我会很高兴 - 为什么滚动仅适用于动画?
I would be glad if anyone could shed some light on this - why does the scrolling only work with animations?
这篇关于重新加载浏览器不会将页面重置为顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!