-
-
Save rickydazla/1390610 to your computer and use it in GitHub Desktop.
"Infinite" scrolling in Shopify collections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% paginate collection.products by 20 %} | |
<ul class="collection-matrix"> | |
{% for product in collection.products %} | |
<li id="product-{{ forloop.index | plus:paginate.current_offset }}"> | |
{% include 'product' with product %} | |
</li> | |
{% endfor %} | |
<li class="top"><a href="#collectionpage">Back to Top</a> ↑</li> | |
{% if paginate.next %} | |
<li class="more">↓ <a href="{{ paginate.next.url }}">More</a></li> | |
{% endif %} | |
</ul> | |
<div id="product-list-foot"></div> | |
{% endpaginate %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pInfScrLoading = false; | |
var pInfScrDelay = 100; | |
function pInfScrExecute() { | |
if($(document).height() - 800 < ($(document).scrollTop() + $(window).height())) { | |
var loadingImage; | |
pInfScrNode = $('.more').last(); | |
pInfScrURL = $('.more a').last().attr("href"); | |
if(!pInfScrLoading && pInfScrNode.length > 0 && pInfScrNode.css('display') != 'none') { | |
$.ajax({ | |
type: 'GET', | |
url: pInfScrURL, | |
beforeSend: function() { | |
pInfScrLoading = true; | |
loadingImage = pInfScrNode.clone().empty().append('<img src=\"http://cdn.shopify.com/s/files/1/0068/2162/assets/loading.gif?105791\" />'); | |
loadingImage.insertAfter(pInfScrNode); | |
pInfScrNode.hide(); | |
}, | |
success: function(data) { | |
// remove loading feedback | |
pInfScrNode.next().remove(); | |
var filteredData = $(data).find(".collection-matrix"); | |
filteredData.insertBefore( $("#product-list-foot") ); | |
loadingImage.remove(); | |
pInfScrLoading = false; | |
}, | |
dataType: "html" | |
}); | |
} | |
} | |
} | |
$(document).ready(function () { | |
$(window).scroll(function(){ | |
$.doTimeout( 'scroll', pInfScrDelay, pInfScrExecute); | |
if( $(document).height() - 800 > $(document).scrollTop() + $(window).height() ) { | |
pInfScrDelay = 100; | |
} | |
}); | |
}); | |
// https://github.com/cowboy/jquery-dotimeout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
working only one next page anyone help pl
collection.liquid is
Load More
and the js script is
var pInfScrLoading = false;
var pInfScrDelay = 100;
function pInfScrExecute() {$(document).height() - 800 > $ (document).scrollTop() + $(window).height() ) {
if($(document).height() - 800 < ($(document).scrollTop() + $(window).height())) {
var loadingImage;
pInfScrNode = $('#more p').last();
pInfScrURL = $('#more p a').last().attr("href");
if(!pInfScrLoading && pInfScrNode.length > 0 && pInfScrNode.css('display') != 'none') {
$.ajax({
type: 'GET',
url: pInfScrURL,
beforeSend: function() {
pInfScrLoading = true;
loadingImage = pInfScrNode.clone().empty().append('<img src="http://cdn.shopify.com/s/files/1/0068/2162/assets/loading.gif?105791\" />');
loadingImage.insertAfter(pInfScrNode);
pInfScrNode.hide();
},
success: function(data) {
// remove loading feedback
pInfScrNode.next().remove();
var filteredData = $(data).find(".gird_pro");
filteredData.insertBefore( $("#product-list-foot") );
loadingImage.remove();
pInfScrLoading = false;
},
dataType: "html"
});
}
}
}
$(document).ready(function () {
$(window).scroll(function(){
$.doTimeout( 'scroll', pInfScrDelay, pInfScrExecute);
if(
pInfScrDelay = 100;
}
});
});