UNPKG

swiper

Version:

Most modern mobile touch slider and framework with hardware accelerated transitions

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