jQuery page transition and browser history

前端 未结 4 592
自闭症患者
自闭症患者 2020-12-09 22:34

I\'m working with jQuery to have a fade-in effect on my html page, which works just fine. However, when I hit the back-button in my browser, I go to the right url but get a

4条回答
  •  无人及你
    2020-12-09 22:46

    In the function above, the linkLocation variable is no longer available because it is out of scope.

    Try this instead:

    $("body").css("display", "none");
    $("body").fadeIn(1500);
    $("a.transition").click(function(event){
        event.preventDefault();
        linkLocation = this.href;
        $("body").fadeOut(500, function() {
            window.location = linkLocation;
        });
    });
    

    Edit: So I fixed your code, but that wasn't the question. :)

    Apparently, the jQuery(document).ready() isn't fired when you hit the back button. You can try this near the top of the page.

    history.navigationMode = 'compatible';
    

    Source: Is there a cross-browser onload event when clicking the back button?

提交回复
热议问题