SHOW:
|
|
- or go back to the newest paste.
| 1 | <infinite-scroll data-next="{{ next_page }}" data-page-size="{{ page_size }}" data-end-text="{{ end_text }}">
| |
| 2 | {% if page_size > 1 %}
| |
| 3 | <div class="loadingBox"> | |
| 4 | <span id="loading_1" class="loadingScroll"> </span> | |
| 5 | <span id="loading_2" class="loadingScroll"> </span> | |
| 6 | <span id="loading_3" class="loadingScroll"> </span> | |
| 7 | <span id="loading_4" class="loadingScroll"> </span> | |
| 8 | <span id="loading_5" class="loadingScroll"> </span> | |
| 9 | <span id="loading_6" class="loadingScroll"> </span> | |
| 10 | <span id="loading_7" class="loadingScroll"> </span> | |
| 11 | <span id="loading_8" class="loadingScroll"> </span> | |
| 12 | </div> | |
| 13 | {% endif %}
| |
| 14 | </infinite-scroll> | |
| 15 | <div class="scrollToTopButton">Scroll To Top</div> | |
| 16 | <style> | |
| 17 | infinite-scroll {
| |
| 18 | position: relative; | |
| 19 | width: 100%; | |
| 20 | font-weight: 600; | |
| 21 | display: flex; | |
| 22 | align-items: center; | |
| 23 | justify-content: center; | |
| 24 | transition: all 0.5s ease; | |
| 25 | } | |
| 26 | .loadingBox {
| |
| 27 | position: relative; | |
| 28 | width: 234px; | |
| 29 | height: 28px; | |
| 30 | margin: auto; | |
| 31 | } | |
| 32 | .loadingScroll {
| |
| 33 | position: absolute; | |
| 34 | top: 0; | |
| 35 | background-color: rgb(0, 0, 0); | |
| 36 | width: 28px; | |
| 37 | height: 28px; | |
| 38 | animation-name: loading_animation; | |
| 39 | -o-animation-name: loading_animation; | |
| 40 | -ms-animation-name: loading_animation; | |
| 41 | -webkit-animation-name: loading_animation; | |
| 42 | -moz-animation-name: loading_animation; | |
| 43 | animation-duration: 1.5s; | |
| 44 | -o-animation-duration: 1.5s; | |
| 45 | -ms-animation-duration: 1.5s; | |
| 46 | -webkit-animation-duration: 1.5s; | |
| 47 | -moz-animation-duration: 1.5s; | |
| 48 | animation-iteration-count: infinite; | |
| 49 | -o-animation-iteration-count: infinite; | |
| 50 | -ms-animation-iteration-count: infinite; | |
| 51 | -webkit-animation-iteration-count: infinite; | |
| 52 | -moz-animation-iteration-count: infinite; | |
| 53 | animation-direction: normal; | |
| 54 | -o-animation-direction: normal; | |
| 55 | -ms-animation-direction: normal; | |
| 56 | -webkit-animation-direction: normal; | |
| 57 | -moz-animation-direction: normal; | |
| 58 | transform: scale(0.3); | |
| 59 | -o-transform: scale(0.3); | |
| 60 | -ms-transform: scale(0.3); | |
| 61 | -webkit-transform: scale(0.3); | |
| 62 | -moz-transform: scale(0.3); | |
| 63 | } | |
| 64 | .scrollToTopButton {
| |
| 65 | position: fixed; | |
| 66 | bottom: 20px; | |
| 67 | right: 149px; | |
| 68 | background: #ececec; | |
| 69 | padding: 5px 10px; | |
| 70 | z-index: 1; | |
| 71 | cursor: pointer; | |
| 72 | border-radius: 5px; | |
| 73 | } | |
| 74 | #loading_1 {
| |
| 75 | left: 0; | |
| 76 | animation-delay: 0.6s; | |
| 77 | -o-animation-delay: 0.6s; | |
| 78 | -ms-animation-delay: 0.6s; | |
| 79 | -webkit-animation-delay: 0.6s; | |
| 80 | -moz-animation-delay: 0.6s; | |
| 81 | } | |
| 82 | #loading_2 {
| |
| 83 | left: 29px; | |
| 84 | animation-delay: 0.75s; | |
| 85 | -o-animation-delay: 0.75s; | |
| 86 | -ms-animation-delay: 0.75s; | |
| 87 | -webkit-animation-delay: 0.75s; | |
| 88 | -moz-animation-delay: 0.75s; | |
| 89 | } | |
| 90 | #loading_3 {
| |
| 91 | left: 58px; | |
| 92 | animation-delay: 0.9s; | |
| 93 | -o-animation-delay: 0.9s; | |
| 94 | -ms-animation-delay: 0.9s; | |
| 95 | -webkit-animation-delay: 0.9s; | |
| 96 | -moz-animation-delay: 0.9s; | |
| 97 | } | |
| 98 | #loading_4 {
| |
| 99 | left: 88px; | |
| 100 | animation-delay: 1.05s; | |
| 101 | -o-animation-delay: 1.05s; | |
| 102 | -ms-animation-delay: 1.05s; | |
| 103 | -webkit-animation-delay: 1.05s; | |
| 104 | -moz-animation-delay: 1.05s; | |
| 105 | } | |
| 106 | #loading_5 {
| |
| 107 | left: 117px; | |
| 108 | animation-delay: 1.2s; | |
| 109 | -o-animation-delay: 1.2s; | |
| 110 | -ms-animation-delay: 1.2s; | |
| 111 | -webkit-animation-delay: 1.2s; | |
| 112 | -moz-animation-delay: 1.2s; | |
| 113 | } | |
| 114 | #loading_6 {
| |
| 115 | left: 146px; | |
| 116 | animation-delay: 1.35s; | |
| 117 | -o-animation-delay: 1.35s; | |
| 118 | -ms-animation-delay: 1.35s; | |
| 119 | -webkit-animation-delay: 1.35s; | |
| 120 | -moz-animation-delay: 1.35s; | |
| 121 | } | |
| 122 | #loading_7 {
| |
| 123 | left: 175px; | |
| 124 | animation-delay: 1.5s; | |
| 125 | -o-animation-delay: 1.5s; | |
| 126 | -ms-animation-delay: 1.5s; | |
| 127 | -webkit-animation-delay: 1.5s; | |
| 128 | -moz-animation-delay: 1.5s; | |
| 129 | } | |
| 130 | #loading_8 {
| |
| 131 | left: 205px; | |
| 132 | animation-delay: 1.64s; | |
| 133 | -o-animation-delay: 1.64s; | |
| 134 | -ms-animation-delay: 1.64s; | |
| 135 | -webkit-animation-delay: 1.64s; | |
| 136 | -moz-animation-delay: 1.64s; | |
| 137 | } | |
| 138 | ||
| 139 | /* Pristege */ | |
| 140 | [class^="pagination"], [class^="Pagination"], .pagination {
| |
| 141 | display: none !important; | |
| 142 | } | |
| 143 | ||
| 144 | .js .features--show-element-staggering .ProductList--grid div.ProductItem {
| |
| 145 | visibility: visible; | |
| 146 | } | |
| 147 | ||
| 148 | .js .product-card[reveal-on-scroll="true"] {
| |
| 149 | opacity: 1; | |
| 150 | } | |
| 151 | ||
| 152 | @keyframes loading_animation {
| |
| 153 | 0% {
| |
| 154 | transform: scale(1); | |
| 155 | background-color: rgb(0, 0, 0); | |
| 156 | } | |
| 157 | 100% {
| |
| 158 | transform: scale(0.3); | |
| 159 | background-color: rgb(255, 255, 255); | |
| 160 | } | |
| 161 | } | |
| 162 | @-o-keyframes loading_animation {
| |
| 163 | 0% {
| |
| 164 | -o-transform: scale(1); | |
| 165 | background-color: rgb(0, 0, 0); | |
| 166 | } | |
| 167 | 100% {
| |
| 168 | -o-transform: scale(0.3); | |
| 169 | background-color: rgb(255, 255, 255); | |
| 170 | } | |
| 171 | } | |
| 172 | @-ms-keyframes loading_animation {
| |
| 173 | 0% {
| |
| 174 | -ms-transform: scale(1); | |
| 175 | background-color: rgb(0, 0, 0); | |
| 176 | } | |
| 177 | 100% {
| |
| 178 | -ms-transform: scale(0.3); | |
| 179 | background-color: rgb(255, 255, 255); | |
| 180 | } | |
| 181 | } | |
| 182 | @-webkit-keyframes loading_animation {
| |
| 183 | 0% {
| |
| 184 | -webkit-transform: scale(1); | |
| 185 | background-color: rgb(0, 0, 0); | |
| 186 | } | |
| 187 | 100% {
| |
| 188 | -webkit-transform: scale(0.3); | |
| 189 | background-color: rgb(255, 255, 255); | |
| 190 | } | |
| 191 | } | |
| 192 | @-moz-keyframes loading_animation {
| |
| 193 | 0% {
| |
| 194 | -moz-transform: scale(1); | |
| 195 | background-color: rgb(0, 0, 0); | |
| 196 | } | |
| 197 | 100% {
| |
| 198 | -moz-transform: scale(0.3); | |
| 199 | background-color: rgb(255, 255, 255); | |
| 200 | } | |
| 201 | } | |
| 202 | </style> | |
| 203 | <script> | |
| 204 | class InfiniteScroll extends HTMLElement {
| |
| 205 | constructor() {
| |
| 206 | super(); | |
| 207 | this.initGrid(); | |
| 208 | this.init(); | |
| 209 | this.page = 1; | |
| 210 | this.scrollToTopBtn = document.querySelector(".scrollToTopButton");
| |
| 211 | this.scrollToTopBtn.addEventListener( | |
| 212 | "click", | |
| 213 | this.scrollToTopFx.bind(this) | |
| 214 | ); | |
| 215 | } | |
| 216 | ||
| 217 | initGrid() {
| |
| 218 | const gridOptions = [".ProductListWrapper", "#main-collection-product-grid", "#product-grid", ".product-list"]; | |
| 219 | for (let gridName of gridOptions) {
| |
| 220 | let grid = document.querySelector(gridName); | |
| 221 | if (grid) {
| |
| 222 | this.gridName = gridName; | |
| 223 | this.gridContainer = grid; | |
| 224 | break; | |
| 225 | } | |
| 226 | } | |
| 227 | } | |
| 228 | ||
| 229 | init() {
| |
| 230 | const observer = new IntersectionObserver(this.revealItem.bind(this), {
| |
| 231 | root: null, | |
| 232 | threshold: 0.05, | |
| 233 | }); | |
| 234 | observer.observe(this); | |
| 235 | } | |
| 236 | ||
| 237 | fetchNextPage(e) {
| |
| 238 | if (e <= this.dataset.pageSize) {
| |
| 239 | const t = `{{ shop.url }}/${this.dataset.next}`;
| |
| 240 | const i = new URL(t); | |
| 241 | i.searchParams.set("page", e);
| |
| 242 | const r = i.href; | |
| 243 | fetch(`${r}`, { method: "GET", headers: { "Content-Type": "text/html" } })
| |
| 244 | .then((e) => e.text()) | |
| 245 | .then((e) => {
| |
| 246 | const t = new DOMParser().parseFromString(e, "text/html"); | |
| 247 | const i = t.querySelector(this.gridName).innerHTML; | |
| 248 | this.gridContainer.insertAdjacentHTML("beforeend", i);
| |
| 249 | }) | |
| 250 | .catch((e) => {
| |
| 251 | console.error("Error:", e);
| |
| 252 | }); | |
| 253 | } | |
| 254 | if (e == this.dataset.pageSize) {
| |
| 255 | this.innerHTML = `<h2>${this.dataset.endText}</h2>`;
| |
| 256 | } | |
| 257 | } | |
| 258 | revealItem(e, t) {
| |
| 259 | const [i] = e; | |
| 260 | if (!i.isIntersecting) return; | |
| 261 | if (i.target) {
| |
| 262 | this.page++; | |
| 263 | this.fetchNextPage(this.page); | |
| 264 | } | |
| 265 | if (this.page == this.dataset.pageSize) {
| |
| 266 | t.unobserve(i.target); | |
| 267 | } | |
| 268 | } | |
| 269 | scrollToTopFx(e) {
| |
| 270 | document.body.scrollTop = 0; | |
| 271 | document.documentElement.scrollTop = 0; | |
| 272 | e.currentTarget.style.display = "none"; | |
| 273 | } | |
| 274 | } | |
| 275 | customElements.define("infinite-scroll", InfiniteScroll);
| |
| 276 | </script> |