function regularScrollToTop() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; } function smoothScrollToTop() { window.scroll({top: 0, left: 0, behavior: 'smooth'}); } function fadeOut() { var el = document.getElementById('effectiveAppsScrollToTopBtn'); el.style.opacity = 1; (function fade() { if ((el.style.opacity -= .1) < 0) { el.style.display = "none"; } else { requestAnimationFrame(fade); } })(); }; function fadeIn(time) { var el = document.getElementById('effectiveAppsScrollToTopBtn'); el.style.opacity = 0; var last = +new Date(); var tick = function() { el.style.opacity = +el.style.opacity + (new Date() - last) / time; last = +new Date(); if (+el.style.opacity < 1) { (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16); } else { el.style.display = "block"; } }; tick(); } function loadSmoothScrollPolyfill(callback) { var script = document.createElement('script'); script.src = 'https://unpkg.com/smoothscroll-polyfill@0.4.4/dist/smoothscroll.min.js'; var head = document.getElementsByTagName('head')[0], done = false; head.appendChild(script); script.onload = script.onreadystatechange = function() { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { done = true; callback(); script.onload = script.onreadystatechange = null; head.removeChild(script); } }; } function CSTT_main() { console.log('%c------ Colorful Scroll To Top Button by Effective Apps is Initializing ------', 'color: cyan'); console.log('%c------ Contact us at support@effectify.co for help and questions about the app ------', 'color: cyan'); var css = '.js-drawer-open #effectiveAppsScrollToTopBtn { display: none !important; } #effectiveAppsScrollToTopBtn{fill: #5a3535; fill-rule: evenodd;} #effectiveAppsScrollToTopBtn:hover {fill: #000000; fill-rule: evenodd;}'; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); document.head.appendChild(style); style.innerHTML = css; if (window.CSTT_SCRIPT_INJECTED === undefined) { window.CSTT_SCRIPT_INJECTED = true; if ('2' === '2') { if (ShopifyAnalytics.meta.page.pageType !== "home") { return; } } else if ('3' === '2') { if (ShopifyAnalytics.meta.page.pageType !== "product") { return; } } else if ('4' === '2') { if (ShopifyAnalytics.meta.page.pageType !== "collection") { return; } } var scrollerConrainerElement = document.createElement('div'); scrollerConrainerElement.innerHTML = ''; document.body.appendChild(scrollerConrainerElement); window.addEventListener('scroll', function() { if (window.scrollY > 50 && document.getElementById('effectiveAppsScrollToTopBtn').style.display === "none") { fadeIn(300); } else if (window.scrollY < 50 && document.getElementById('effectiveAppsScrollToTopBtn').style.display === "block") { fadeOut(); } }, false); } } if ('scrollBehavior' in document.documentElement.style) { CSTT_main(); } else { loadSmoothScrollPolyfill(CSTT_main); }