swiper
Version:
Most modern mobile touch slider and framework with hardware accelerated transitions
2 lines • 2 kB
JavaScript
import{e as elementChildren}from"../shared/utils.min.mjs";function Parallax({swiper:a,extendParams:e,on:t}){e({parallax:{enabled:!1}});const r="[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]",l=(e,t)=>{const{rtl:r}=a,l=r?-1:1,s=e.getAttribute("data-swiper-parallax")||"0";let i=e.getAttribute("data-swiper-parallax-x"),p=e.getAttribute("data-swiper-parallax-y");const n=e.getAttribute("data-swiper-parallax-scale"),o=e.getAttribute("data-swiper-parallax-opacity"),d=e.getAttribute("data-swiper-parallax-rotate");if(i||p?(i=i||"0",p=p||"0"):a.isHorizontal()?(i=s,p="0"):(p=s,i="0"),i=i.indexOf("%")>=0?parseInt(i,10)*t*l+"%":i*t*l+"px",p=p.indexOf("%")>=0?parseInt(p,10)*t+"%":p*t+"px",null!=o){const a=o-(o-1)*(1-Math.abs(t));e.style.opacity=a}let x=`translate3d(${i}, ${p}, 0px)`;if(null!=n){x+=` scale(${n-(n-1)*(1-Math.abs(t))})`}if(d&&null!=d){x+=` rotate(${d*t*-1}deg)`}e.style.transform=x},s=()=>{const{el:e,slides:t,progress:s,snapGrid:i,isElement:p}=a,n=elementChildren(e,r);a.isElement&&n.push(...elementChildren(a.hostEl,r)),n.forEach(a=>{l(a,s)}),t.forEach((e,t)=>{let p=e.progress;a.params.slidesPerGroup>1&&"auto"!==a.params.slidesPerView&&(p+=Math.ceil(t/2)-s*(i.length-1)),p=Math.min(Math.max(p,-1),1),e.querySelectorAll(`${r}, [data-swiper-parallax-rotate]`).forEach(a=>{l(a,p)})})};t("beforeInit",()=>{a.params.parallax.enabled&&(a.params.watchSlidesProgress=!0,a.originalParams.watchSlidesProgress=!0)}),t("init",()=>{a.params.parallax.enabled&&s()}),t("setTranslate",()=>{a.params.parallax.enabled&&s()}),t("setTransition",(e,t)=>{a.params.parallax.enabled&&((e=a.params.speed)=>{const{el:t,hostEl:l}=a,s=[...t.querySelectorAll(r)];a.isElement&&s.push(...l.querySelectorAll(r)),s.forEach(a=>{let t=parseInt(a.getAttribute("data-swiper-parallax-duration"),10)||e;0===e&&(t=0),a.style.transitionDuration=`${t}ms`})})(t)})}export{Parallax as default};
//# sourceMappingURL=parallax.min.mjs.map