2017-12-19 1 views
2

이 코드를 사용하여 무한 크기의 페이지를 사각형 영역에로드합니다. 내 문제는 재로드가 내 URL에 설정 한 필터링을 캡처하지 않는다는 것입니다. 변수 나 심지어는 url이나 categoryFilter를 내 컬렉션에 '볼'수없는 것처럼 보입니다. .var 지시문을 사용하려고했지만 게으른로드 된 항목은 앞에 정의 된 항목의 범위를 볼 수 없습니다. 아이디어가 부족해서 도움을주세요!squarespace의 무한 스크롤이 카테고리 필터를 가져옵니다.

편집 : 나는 그 해답을 찾았지만 또 다른 질문을 얻었다.

결국 window.location.pathname 대신 window.location.href를 사용하여 결국 매개 변수를 가져올 수있었습니다. IE11에서 작동하지 않는 것을 제외하고 지금은 이것을 검색해야합니다.

<script> 

function infiniteScroll(parent, post) { 

    // Set some variables. We'll use all these later. 
    var postIndex = 1, 
     execute = true, 
     stuffBottom = Y.one(parent).get('clientHeight') + Y.one(parent).getY(), 
     urlQuery = window.location.pathname, 
     postNumber = Static.SQUARESPACE_CONTEXT.collection.itemCount, 
     presentNumber = Y.all(post).size(); 

    Y.on('scroll', function() { 

     if (presentNumber >= postNumber && execute === true) { 
      Y.one(parent).append('<h1>There are no more posts.</h1>') 
      execute = false; 
     } else { 

      // A few more variables. 
      var spaceHeight = document.documentElement.clientHeight + window.scrollY, 
      next = false; 

      /* 
       This if statement measures if the distance from 
       the top of the page to the bottom of the content 
       is less than the scrollY position. If it is, 
       it's sets next to true. 
      */ 
      if (stuffBottom < spaceHeight && execute === true) { 
       next = true; 
      } 

      if (next === true) { 

       /* 
        Immediately set execute back to false. 
        This prevents the scroll listener from 
        firing too often. 
       */ 
       execute = false; 

       // Increment the post index. 
       postIndex++; 

       // Make the Ajax request. 
       Y.io(urlQuery + '?page=' + postIndex, { 
        on: { 
         success: function (x, o) { 
          try { 
           d = Y.DOM.create(o.responseText); 
          } catch (e) { 
           console.log("JSON Parse failed!"); 
           return; 
          } 

          // Append the contents of the next page to this page. 
          Y.one(parent).append(Y.Selector.query(parent, d, true).innerHTML); 

          // Reset some variables. 
          stuffBottom = Y.one(parent).get('clientHeight') + Y.one(parent).getY(); 
          presentNumber = Y.all(post).size(); 
          execute = true; 

         } 
        } 
       }); 
      } 
     } 
    }); 
} 

// Call the function on domready. 
Y.use('node', function() { 
    Y.on('domready', function() { 
     infiniteScroll('#content','.lazy-post'); 
    }); 
}); 


</script> 

답변

0

나는이 스크립트를 내가 원하는대로 작동시킬 수있었습니다.

Static.SQUARESPACE_CONTEXT.collection.itemCount 

을 다음과 같이 jsont와 같은 {collection.categoryFilter}를 얻을 :

Static.SQUARESPACE_CONTEXT.collection.categoryFilter 

또는이 :

Static.SQUARESPACE_CONTEXT.categoryFilter 

그것은 didn를을

은 내가 사용할 수 있다고 생각 내가 대신 변경 했으므로 대신 변경했습니다.

urlQuery = window.location.pathname 

내게 필요한 매개 변수를 준

urlQuery = window.location.href 

합니다. 나는이 스크립트이었다 발생

IE11 문제는

window.scrollY 

내가 IE11 호환

Window.pageYOffset 

로 변경하고 우리가 갈 수 있었다 사용!

관련 문제