我想在jquery中寫一個函數,當單擊一個按鈕時,用戶的滾動位置被保存,然後當頁面加載按鈕指向的鏈接時,滾動位置被檢索。這是我的功能。我不確定是什麼問題,因爲我相對比較新。點擊保存滾動位置,然後檢索?
var scrolltop;
$(document).ready(function(){
$('a.page-numbers').click(function() {
scrolltop = $(document).scrollTop(); // store it
var href = $(this).attr('href');
window.location= href; // I am doing this to force a button to go to a link and temporarily fix a pagination issue if people are curious. Not the current issue at hand.
return false; // Doing this so page doesn't scroll on click
});
});
$(document).ready(function(){
$('html, body').animate({scrollTop: scrolltop}); //not scrolling to where saved
});
獎勵積分的人誰也可以將其移動(IOS,Android等)兼容:)
變量或任何JavaScript,只是**不**持續跨頁面加載。您需要持久存儲。 – adeneo
我可以問你想要什麼類型的永久存儲? – LearntoExcel
那麼,任何可以存儲這些值直到下一頁加載的持久性存儲。本地存儲,Cookie,使用URL或服務器來存儲值等 – adeneo