1
我有一個div滑出屏幕,加載新內容並滑回。 使用jQuery pjax而該部分的偉大工程:popState和動畫 - pjax
$('#menu a').on('click', function(event){
event.preventDefault();
var target = $(this).attr('href');
$('li.current').removeClass("current");
$(this).parent().addClass("current");
$(content).transition({left:$(document).width()}, 900, 'out', function() {
$.pjax({
url: target,
container: '#content',
fragment: '#content',
success: function(){
$(content).transition({ left:'0px'}, 900, 'out');
var contentHeight = $('#content').outerHeight(true)+258+$("#footer").outerHeight(true);
if(contentHeight<parseInt($("body").css("min-height"))){
contentHeight = "100%";
}
$(page).stop(true).animate({height:contentHeight}, 1000, "easeOutCubic");
}
});
});
});
但我不明白這一點做的工作,如果瀏覽器前進/後退使用按鈕。 我嘗試了不同的事情。 在這裏,我發現了一篇不錯的文章,但我不明白:http://artfindertech.wordpress.com/tag/historyapi/
事情是,當你點擊瀏覽器後退按鈕時div的內容發生變化。 然後它滑出,但不回來。 此外,網址更改爲上一頁的一秒,但跳轉到該網站的主要網址。 這裏是我的popState試驗:
$(window).on('pjax:popstate', function() {
$(content).transition({left:$(document).width()}, 900, 'out', function() {
$.pjax({
container: '#content',
fragment: '#content',
success: function(){
$(content).transition({ left:'0px'}, 900, 'out');
var contentHeight = $('#content').outerHeight(true)+258+$("#footer").outerHeight(true);
if(contentHeight<parseInt($("body").css("min-height"))){
contentHeight = "100%";
}
$(page).stop(true).animate({height:contentHeight}, 2000, "easeOutCubic");
}
});
});
});