UNPKG

alpinejs-scroll-to

Version:

Easily add scroll to functionality with options, powered by Alpine JS 🐭

2 lines (1 loc) 626 B
function s(t,{offsetHeader:e=!1,useSmooth:o=!0}){let r=t.href.split("#")[1],l=document.getElementById(r).getBoundingClientRect(),n=0;e&&(n=document.querySelector("[x-scroll-to-header]").clientHeight),window.scrollTo({top:l.top-n,left:0,behavior:o?"smooth":"auto"})}function i({targetId:t,offsetHeader:e=!1,useSmooth:o=!0}){let c=document.getElementById(t).getBoundingClientRect(),l=0;e&&(l=document.querySelector("[x-scroll-to-header]").clientHeight),window.scrollTo({top:c.top-l,left:0,behavior:o?"smooth":"auto"})}function u(t){t.magic("scrollTo",(e,{})=>o=>{if(o.targetId)return i(o);s(e,o)})}var a=u;export{a as default};