1
我正在使用jquery.address插件來使用Ajax動態加載我的#content。我也正在使用一些效果來加載新的#content(即舊的#內容飛出,新進來的頂部,或從側面等),但我認爲這不是問題..Ajax地址保持滾動位置
問題是,在ajax請求之後,滾動位置不會保留,頁面會跳回頂部。
有沒有插件/靈魂?我讀到將當前位置存儲在cookie中並使用$(「html,body」)。animate({scrollTop:x},t);有助於。但是,有沒有更好的更簡單的方法來實現這一目標?
事先感謝!
邁克
編輯
解決:發現瞭解決方案(註釋掉.focus()):
// Selects the proper navigation link
$('#menu a').each(function() {
//console.log($(this).attr('href'));
if (($(this).attr('href') == ($.address.state() + event.path)) {
//$(this).addClass('selected').focus(); // .focus() needs to be commented out in order to prevent to set the focus back to this class
$(this).addClass('selected');
}
else {
$('#menu ul li').removeClass('current-menu-item');
$(this).removeClass('selected');
}
});
發現此問題http://stackoverflow.com/questions/4284596/jquery-address-page-jump-issue-in-scrolling-scenarios-address-wrap但返回false;不適合我。這是用address.wrap()來完成的嗎? – Mike