Shopify themes, liquid, logos, and UX
I had certain problems by implementing Ajaxinate endless scroll:
The issue was that after clicking on a product and clicking the back button, the scroll position was lost. I tried to implement "Snapback cache", to solve the back button issue, but it didn't work properly:
After clicking the back button in the browser, the position was restored perfectly, but the next loaded pages were starting with page 1 again.
So now I implemented the infinite scroll of infinite-scroll.com, they have a quite good solution to solve the back button problem, and a commercial licence is a one time fee of 25$, which is a fair price to me.
So I show you how I implemented infinite-scroll in my minimal theme to save you some time:
{{ 'infinite-scroll.pkgd.js' | asset_url | script_tag }}
$(document).ready(function() {
$('.infiniteloop').infiniteScroll({
// options
path: '.pagination__next',
append: '.loopload',
status: '.page-load-status',
hideNav: '.pagination',
//scrollThreshold: 1000,
});
});
<div class="infiniteloop"> // <----- Start Div ------>
{% for product in collection.products %}
<li class="grid__item grid__item--{{section.id}} {{ grid_item_width }}">
{% include 'product-card-grid', max_height: max_height %}
</li>
{% else %}
{% comment %}
Add default products to help with onboarding for collections/all only.
The onboarding styles and products are only loaded if the
store has no products.
{% endcomment %}
{% if collection.handle == 'all' and collection.all_vendors.size == 0 and collection.all_types.size == 0 %}
<li class="grid__item">
<div class="grid grid--uniform">
{% for i in (1..limit) %}
<div class="grid__item {{ grid_item_width }}">
<div class="grid-view-item">
<a href="#" class="grid-view-item__link">
<div class="grid-view-item__image">
{% capture current %}{% cycle 1, 2, 3, 4, 5, 6 %}{% endcapture %}
{{ 'product-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
</div>
<div class="h4 grid-view-item__title">{{ 'homepage.onboarding.product_title' | t }}</div>
<div class="grid-view-item__meta">
<span class="product-price__price">$19.99</span>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
</li>
{% else %}
{%- assign is_empty_collection = true -%}
{% endif %}
{% endfor %}
</div> // <------ End Div ------->
{% if paginate.pages > 1 %}
{% include 'pagination' %}
{% endif %}
<div class="page-load-status">
<div class="infinite-scroll-request loader-ellips">
more products loading...
</div>
<p class="infinite-scroll-last">End of content</p>
<p class="infinite-scroll-error">No more pages to load</p>
</div>
<p class="pagination">
<a class="pagination__next" href="{{ paginate.next.url }}"></a>
</p>
var bottom = this.top + this.element.clientHeight;
var bottom = Math.max( window.innerHeight, document.body.clientHeight )
scrollThreshold: 1000
I forgot one thing, I added the class "loopload" in the for- loop, just the line below the for loop starts in the collection-template.liquid, so the line looks like this:
<div class="grid__item {{grid_item_width}} loopload">
This seems like the standard install for infinte-scroll.com
Is the back button/save position working? Did you have to update/add any additional options to make that work?
Thanks for your post. I'm using minimal theme as well. Just to be sure, I can start with going to infinite-scroll.com or I need to add some codes before that? Thanks. Al
Thanks for this! but how did you solve the retain-position-in-infinite scroll problem? When I hit back on browser, i get loaded from page 2 without content from page 1
Like in the demo. It is loaded beginning page 2 after back button. So I put in a title with adding " - page 2" to the collection title. so at least the user knows he's on page 2.
Good solution!
I also can't seem to figure out how to stop infinite scroll from making requests for new pages when there aren't any... the instructions in the demo don't work on my solution could you possibly show how yours works?
Thanks post can you please try this
Hi,
I have tried this method with no luck, infinite scroll works for me, except for my one problem
I only start infinite scroll if I have more than 29 items on my collection page, as I have a pagination of 30 products per page. This is what I put in my theme.js:
$(function () {
if ($('.loopload').length>29){
var $container = $('.ajaxloop').infiniteScroll({
// options
path: '.pagination__next',
append: '.loopload',
status: '.page-load-status',
hideNav: '.pagination',
scrollThreshold: 1400,
});
$('#next-pagination-check').addClass('initialised');
}
});
I still keep getting all these page requests when scrolling to the bottom even trying your method
what is the problem for the user with the page requests? Is it visible at the end of the scroll list that new requests are sent?
In my collection-template.liquid, I have this code
<p class="pagination" id="AjaxPagination">
{% if paginate.pages > 1 %}
{% if paginate.next %}
<a id="next-pagination-check" class="pagination__next" href="{{ paginate.next.url }}">Nächste Seite</a>
<div class="page-load-status">
<div class="infinite-scroll-request loader-ellips">
<div class="loader-ellips">
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
</div>
</div>
<p class="infinite-scroll-last"></p>
<p class="infinite-scroll-error">Seitenende</p>
</div>
{% endif %}
{% endif %}
</p>
Just received a message, v4 for infinite-scroll.com was just released. Did it change anything in the behaviour with your issue?
I will see if the new Infinite Scroll solves this. Luckily there is no noticeable visual problem for the user... but I don't like the idea of the site potentially loading loads more data unnecessarily. Thanks!
I have a problem with my scroll- it freezes on some images and won't move to the next image. When I get frustrated and try to swipe or click back the page goes black and blank and I cannot go back to my website at all. Is this the solution to that?
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024