重新加载浏览器不会将页面重置为顶部 [英] Reload browser does not reset page to top

查看:200
本文介绍了重新加载浏览器不会将页面重置为顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想当你点击刷新时,浏览器应该将你的页面重置为顶部?我正在使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆