浏览器后退按钮VS链接至previous页面的行为jQuery的地址的区别按钮、浏览器、区别、行为

2023-09-10 19:02:25 作者:明月清风晓星尘

我的问题是最好的这个截屏记录我描述: http://www.youtube .COM /手表?ν= AI-p_jqzOdU

My problem is best described with this screencast I recorded: http://www.youtube.com/watch?v=aI-p_jqzOdU

我使用jQuery的地址插件Ajax的深层链接。对于那些谁不知道如何jQuery的地址的工作原理,它的工作原理是听与的变化()方法哈希变化。 pressing后退按钮和pressing中转至previous页面的URL的行为应该以同样的方式,因为他们所说的相同的事件处理程序的超链接。

I'm using the jQuery Address plugin for Ajax deep-linking. For those who don't know how jQuery address works, it works by listening to the hash changes with the change() method. Pressing the back button and pressing a hyperlink that goes to the previous page URL should behave the same way because they call the same event handler.

这是伪code:

$address.change(function(event) {
    if (event.value != '/') { // is the image link
        Get the URL to be loaded
        Create an overlay, append it to body and set its height, width, opacity
        Put overlay on top of gallery
        Load URL into overlay then fade it in
        Set BODY to overflow: hidden
    } else { // is the gallery link
        Set BODY to overflow: auto
        Fade out overlay then remove it
    }
});

如果你看录像,你会看到pressing链接到previous页面导致页面的滚动跳回到0 pressing浏览器后退按钮使其保持其在所需的行为。

If you watch the video, you'll see that pressing the link to the previous page causes the scroll of the page to jump back to 0. Pressing the browser back button keeps it which the the desired behavior.

什么地方出错了?

推荐答案

好吧,我想我知道什么是错的。历史会记住previous页面的滚动,从而后退按钮保持滚动。链接到previous页面生成一个新的历史状态,因此你是不是回previous状态,但带有滚动新的状态为零。

Ok I think I know what's wrong. The history remembers the scroll of the previous page and thus the back button keeps the scroll. The link to previous page generates a new history state and thus you are not back to a previous state but a new state with scroll at zero.

 
精彩推荐
图片推荐