サイトの次のページから必要なコンテンツを介して無限スクロールの読み込みをエミュレートする tumblr ページ用の小さなjQueryスクリプトを作成しています (これはtumblrサイトなので、ページネーションは問題ありません)。
いくつかの無限スクロールプラグインがあることは知っていますが、私が試したものはすべてうまくいきませんでした。私はそのすべての機能を必要としません。スクリプトは必要な新しい要素をロードしますが、問題は毎回 2 つのページからコンテンツをロードすることです。そして、明らかに、代わりに 1 つのページ コンテンツのみをロードする必要があります。jQuery.get()
jQueryは次 のとおりです。
$(document).ready(function() {
"use strict";
var nextPage = 2;
var totalPages = {TotalPages};
var url = '/page/'; // base url
$(document).on('scroll', function() {
if (nextPage <= totalPages) { // if exist new pages
if ($(window).scrollTop()== $(document).height() - $(window).height()) { // when reach the page bottom
$.get(url + nextPage, function(data){ // get the next page
$(data).find(".post").appendTo(".posts"); // filter content we want and append it to the actual page element
picturefill(); // reload picturefill,making the new images responsive
});
nextPage++; // increment nextpage counter
};
} else { // exit if no more pages
return;
}
});
});
読み込まれるコンテンツは次のとおりです。
<div class="posts">
<article class="photo-container post" id="{PostID}" data-reblog="{ReblogURL}">
<div class=" picturefill" data-picture data-alt="" data-class="photo">
<div class="picturefill" data-src="{PhotoURL-HighRes}" ></div>
<div class="picturefill" data-src="{PhotoURL-500}" data-media="(max-width: 568px)"></div>
<div class="picturefill" data-src="{PhotoURL-250}" data-media="(max-width: 250px)"></div>
<img alt="" class="photo" src="http://img.jpg"> <!-- generated by picturefill -->
<noscript><img class="photo" src="{PhotoURL-HighRes}" alt=""></noscript>
</div>
<!-- MORE CODE -->
</article>
レスポンシブ画像にPicturefillを使用していますが、うまく機能します。誰にもアイデアがありますか?ありがとう。