UNPKG

alrdy-animate

Version:

A library to handle animations on scroll with GSAP integration.

1 lines 2.02 kB
"use strict";(this.webpackChunkAlrdyAnimate=this.webpackChunkAlrdyAnimate||[]).push([[525],{687:(e,t,r)=>{function a(e,t){return{marquee:function(t,r,a,n){return function(e,t,r,a,n){var i=n.includes("right"),o=n.includes("hover"),s=n.includes("paused"),u=n.includes("switch"),c=e.querySelector("[aa-marquee-scroller]"),l=e.querySelector("[aa-marquee-items]");if(c&&l){for(var d=window.innerWidth<479?.5:window.innerWidth<991?.75:1,m=parseInt(c.getAttribute("aa-marquee-scroller"))||0,f=r*(l.offsetWidth/window.innerWidth)*d,w=parseInt(l.getAttribute("aa-marquee-items"))||2,g=document.createDocumentFragment(),h=0;h<w;h++)g.appendChild(l.cloneNode(!0));c.appendChild(g);var q=e.querySelectorAll("[aa-marquee-items]"),p=i?-1:1,v=p;if(!s){var b=t.to(q,{xPercent:-100,repeat:-1,duration:f,ease:"linear",force3D:!0,willChange:"transform"}).totalProgress(.5);if(t.set(q,{xPercent:i?-100:100,force3D:!0,willChange:"transform"}),b.play(),b.timeScale(v),e.classList.add("marquee-normal"),u){var y=v;new MutationObserver((function(t){if(t.some((function(e){return"data-scroll-direction"===e.attributeName}))){var r="up"===(document.body.getAttribute("data-scroll-direction")||"down"),a=r?-p:p;a!==y&&(y=a,v=a,b.timeScale(a)),e.classList.toggle("marquee-normal",!r),e.classList.toggle("marquee-inverted",r)}})).observe(document.body,{attributes:!0,attributeFilter:["data-scroll-direction"]})}o&&(e.addEventListener("mouseenter",(function(){t.to(b,{timeScale:.25*v,duration:.3,ease:"power2.out"})})),e.addEventListener("mouseleave",(function(){t.to(b,{timeScale:v,duration:.3,ease:"power2.out"})})))}if(m>0){c.style.marginLeft="-".concat(m,"%"),c.style.width="".concat(2*m+100,"%");var A=i?-m:m;t.timeline({scrollTrigger:{trigger:e,start:"0% 100%",end:"100% 0%",scrub:!!a&&(parseFloat(a)||!0)}}).fromTo(c,{x:"".concat(A,"vw")},{x:"".concat(-A,"vw"),ease:"none"})}}else console.warn("Marquee elements not found. Required: [aa-marquee-scroller] and [aa-marquee-items]")}(t,e,r,a,n)}}}r.r(t),r.d(t,{createMarqueeAnimations:()=>a})}}]);