實現頁面指定div中滑塊滑動距離

var btn=sessionStorage.getItem("btn");

if(btn!=null || btn!=undefined){
    $('.btn-icon').scrollLeft(btn);
}

function showPurInfo(id){
    sessionStorage.setItem("btn",0);

    window.location.href='${ctx}/public/sunshinePurchase/look?id='+id
}
function showNewInfo(id){
    var kuaiWidth=parseInt($(".tab-click").css("width").substr(0,$('.tab-click').css("width").length-2))*1;
    var divWidth=$('.btn-icon').css("width").substr(0,$('.btn-icon').css("width").length-2)
    sessionStorage.setItem("btn",divWidth-kuaiWidth);

    window.location.href='${ctx}/news/one/'+id
}

兩個function是跳轉其他頁面的方法,運行方法的同事保存了btn值,btn的值就是要自動滑動的距離.當頁面加載的時候會先從sessionStorage中獲取btn的值,如果沒有頁面就是默認位置,如果我們點擊過這兩個跳轉頁面的方法,那麼sessionStorage中就會有值,我們使用 (.btnicon).scrollLeft(btn);使 (‘.btn-icon’).scrollTop(btn); ,其中$(‘.btn-icon’).是抓取的jquery對象,換成自己的div即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章