| 1 |
"use strict";var merchant=merchant||{};merchant.scrollTo={domReady:function(t){if("function"==typeof t)return"interactive"===document.readyState||"complete"===document.readyState?t():void document.addEventListener("DOMContentLoaded",t,!1)},init:function(){var t=document.querySelectorAll("[data-merchant-scroll-to]");"null"!=typeof t&&t.forEach(function(e){e.addEventListener("click",function(t){t.preventDefault(),merchant.scrollTo.scrollTo(e)})})},scrollTo:function(t){var e=t.getAttribute("data-merchant-scroll-to"),o=t.getAttribute("data-merchant-scroll-to-offset")||0;e&&(e=document.querySelector(e).getBoundingClientRect(),e=parseInt(e.top+window.pageYOffset-o),window.dispatchEvent(new Event("mrc-scrollto.before.scrolling"),{eventData:{context:t}}),window.scrollTo({top:e,behavior:"smooth"}),setTimeout(function(){window.dispatchEvent(new Event("mrc-scrollto.after.scrolling",{eventData:{context:t}}))},500))}},merchant.scrollTo.domReady(function(){merchant.scrollTo.init()}); |