2014-04-11 2 views
0

사용자가 페이지 맨 아래로 스크롤 할 때 더 많은 게시물을로드하고 싶은 블로그를 만듭니다. 그러나 다른 .html 파일에서 내용을 가져 오는 jQuery 플러그인을 사용하고 싶지 않습니다. 대신 모든 게시물을 한 페이지에 넣고 표시되는 양을 제한하고 사용자가 스크롤을 계속하면서 몇 개 더로드하려고합니다.외부 콘텐츠가없는 무한 스크롤

이 작업을 수행하는 데 도움이되는 플러그인 또는 스 니펫이 있습니까?

예 :

 <-- Visible to users --> 
    <article> Pretend this is a preview for an article on a blog</article> 
    <article> Pretend this is a preview for an article on a blog</article> 
    <article> Pretend this is a preview for an article on a blog</article> 
    <-- End of Page --> 

    <-- Infinite Scroll Load (Was Hidden Now Visible) --> 
    <article> Pretend this is a preview for an article on a blog</article> 
    <article> Pretend this is a preview for an article on a blog</article> 
    <article> Pretend this is a preview for an article on a blog</article> 
    <-- End of Page --> 

그리고 반복 .. 어떤 도움을 주시면 감사하겠습니다

!

+0

이유는 무엇입니까? 무한 스크롤이 페이지의 모든 컨텐츠를 갖는 것 이상의 유일한 이점은 모든 컨텐츠를 맨 앞에 로딩하는 것을 피할 수 있다는 것입니다. 이를 없애면 스크롤바가 아무런 효과가 없도록 이상하게 작동하게됩니다. – Quentin

답변

0

$(function() { 
    $("body").css("height", $(document).height() + 1) 
     .find("article").each(function (i, el) { 
     $(el).not(":nth-last-of-type(n+4)").hide() 
      .filter(":nth-of-type(4)").on("click.y", function() { 
      $("body").animate({ 
       scrollTop: "0px" 
      }, 1000) 
     }); 
    }); 
    $(document).on("scroll", { 
     "scrolled": false 
    }, function (e) { 
     if (!e.data.scrolled) { 
      var el = $("article:nth-of-type(n+4)"); 
      $(el).show(1000); 
      e.data.scrolled = true; 
     }; 
     if (e.data.scrolled) { 
      $(el).on("click", function (e) { 
       $(e.target).hide(1000); 
      }); 
     }; 
     if ($("article:nth-of-type(n+4)").css("display") === "none") { 
      e.data.scrolled = false; 
     }; 
     return false 
    }); 
}); 

jsfiddle이 (패턴)을 시도 http://jsfiddle.net/guest271314/vTKpP/