問題場景: 我有一個頁面查看下一頁信息需要Ajax累加頁面,當(dāng)加載了以后點(diǎn)擊跳轉(zhuǎn)鏈接,跳轉(zhuǎn)之后在微信里點(diǎn)擊返回上一頁直接自動刷新頁面,現(xiàn)在需要他返回上一頁保存之前加載的數(shù)據(jù)并定位到當(dāng)前點(diǎn)擊跳轉(zhuǎn)的地方 解決辦法: 查了點(diǎn)資料,決定先用sessionStorage在每次請求ajax后存儲當(dāng)前加載完的所有頁面,然后獲取每次手指滑動頁面的位置,存儲在緩存中,返回頁面時根據(jù)緩存顯示數(shù)據(jù)并且定位
$(function(){ var value = sessionStorage.getItem("list_id"); if(value !== null && value !== undefined && value !== ''){ setTimeout(function(){ var h = sessionStorage.getItem("scrolltop_id"); $(document).scrollTop(h); },500) } $(document).on('touchstart',function(evt){ var scroll = $(this).scrollTop(); sessionStorage.setItem("scrolltop_id", scroll); }) var storage_html = $('#grid').html(); sessionStorage.setItem("list_id", storage_html);})新聞熱點(diǎn)
疑難解答