-
Notifications
You must be signed in to change notification settings - Fork 1
/
load more product button.txt
82 lines (66 loc) · 2.25 KB
/
load more product button.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
1. Go to your collection template and fid this code section
<ul class="grid grid--uniform{% if collection.products_count > 0 %} grid--view-items{% endif %}">
{% for product in collection.products %}
add class and date:
data-next-url="{{paginate.next.url}}"
class="products-on-page"
example:
<ul data-next-url="{{paginate.next.url}}" class="products-on-page grid grid--uniform{% if collection.products_count > 0 %} grid--view-items{% endif %}">
2. second html code end of the </ul> tag find this code and add after this code
{% else %}
{%- assign is_empty_collection = true -%}
{% endif %}
{% endfor %}
</ul>
code:
<div class="load-more">
<a class="load-more_btn btn" onclick="loadMoreProducts()">Load More</a>
<div class="load-more_spinner"></div>
</div>
3. add css code for designing load more button
.load-more{text-align:center;margin-top:45px;}
.load-more_spinner{
display: none;
width: 35px;
height: 35px;
border: 5px solid #f3f3f3;
border-top: 5px solid #3a3a3a;
border-radius: 50%;
margin-left: auto;
margin-right: auto;
animation: 2s spin linear infinite;
}
@keyframes spin{
0%{transform:rotate(0deg)}
100%{transform:rotate(360deg)}
}
4. Go to assets and create a new collection-load-more.js file and paste this code:
var products_on_page = $('.products-on-page');
var next_url = products_on_page.data('next-url');
var load_more_btn = $('.load-more_btn ');
var load_more_spinner = $('.load-more_spinner');
function loadMoreProducts() {
$.ajax(
{
url: next_url,
type: 'GET',
dataType: 'html',
beforeSend: function(){
load_more_btn.hide();
load_more_spinner.show();
}
}
).done(function(next_page){
load_more_spinner.hide();
var new_products = $(next_page).find('.products-on-page');
var new_url = new_products.data('next-url');
if(new_url)
load_more_btn.show();
next_url = new_url;
products_on_page.append(new_products.html());
})
}
5. Go to layout area paste this code on the theme.liquid file:
{% if template contains 'collection' %}
<script src="{{ 'collection-load-more.js' | asset_url }}" defer="defer"></script>
{%endif%}