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

引入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);
        }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容