JavaScript

移动端跳转页面后返回原来的位置

2017-12-14  本文已影响30人  LuckyS007

引入store.js
思路:
1.记录页面点击位置的高度,和页面的路径
2.获取页面的页码数和商品数
3.123返回出去是继续往下加载456

//跳转
    that.go = function(id){

      try{
          var obj ={ 
            href:location.href,
            heigth:that.heigth()
          };
//页面分页加载的情况下
          if(location.href.indexOf('classification.html')>0){
           var $that =$('#productList-box');
           var length = $that.find('.product_card').length;
           obj.html = $('#productList-box').html();
           obj.count = length;

          }
          store.set('High',obj);
      }catch(e){}
       this.location.href ="http://"+host+ doaminName + "/goods/detail?productid="+id;
    }
//函数
that.setheigth=function(time)
    {
      var cacheObj = store.get('High');
        if(cacheObj!=undefined)
        {
             try{
               var url = cacheObj.href;
               var height = cacheObj.heigth;
               if(location.href==url){
               setTimeout('$(document).scrollTop(' + height + ')', time||800);
               store.remove('High');
               }else{
                store.remove('High');
               }
             }catch(e){
              console.dir(e);

             }

        }  
      
    }

//相应页面调用
try{
            var list = store.get('High');
            if(list!=undefined){
                $('#productList-box').html(list.html);                
                setheigth(1200);
                $("img").lazyload();
                $.get('/act/productList',searchParams).done(function(data){
                  proCount =data.count;
                  searchParams.pageNumber = list.count/searchParams.rowsPerPage;
                  
                })

            }else{
              getProListData(); 
            }  
        }catch(e){
          console.dir(e);
        }
上一篇下一篇

猜你喜欢

热点阅读