Created
November 20, 2018 16:37
-
-
Save atikju/ea86cd9863820f0b5849be464b60e086 to your computer and use it in GitHub Desktop.
Shopify - Infinite Scrolling on Collection Pages
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 24 %} | |
| <div class="devProductContainer"> | |
| {% for product in collection.products %} | |
| {% include 'product-loop' %} | |
| {% endfor %} | |
| </div> | |
| <!--pagination links--> | |
| <div id="pagination"> {{ paginate | default_pagination }} </div> | |
| {% endpaginate %} | |
| <style> | |
| #pagination{ display: none; } | |
| </style> |
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
| //This file needs to be hooked at the bottom of theme.liquid right before the </body> | |
| {% if template.name contains 'collection' %} | |
| {% assign product_per_page = 24 %} | |
| <script> | |
| $(document).ready(function() { | |
| var counter = 2 | |
| var pages = Math.ceil('{{ collection.all_products_count }}' / {{ product_per_page }}); | |
| var maxCount = pages + 1; | |
| console.log("Pages Found: " + pages); | |
| console.log("Collection Title: {{ collection.handle }}"); | |
| $('#pagination a').on('click' , function(e) { | |
| e.preventDefault(); | |
| var getUrl = "{{shop.url}}/collections/{{ collection.handle }}?page="+counter; | |
| console.log(getUrl); | |
| $.ajax({ | |
| url: getUrl, | |
| type:'GET', | |
| // beforeSend: function() { | |
| // showPopup('.loading'); | |
| // }, | |
| success: function(data){ | |
| //hidePopup('.loading'); | |
| $(".devProductContainer").append($(data).find('.devProductContainer').html()); | |
| counter++; | |
| if(counter == maxCount ) { | |
| $('#more').empty(); | |
| } | |
| } | |
| }); | |
| }); | |
| $(window).scroll(function() { | |
| if($(window).scrollTop() + $(window).height() == $(document).height()) { | |
| $('#pagination a').eq(0).trigger('click'); | |
| console.log('clicked'); | |
| } | |
| }); | |
| }); | |
| </script> | |
| {% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment