UNPKG

swiper

Version:

Most modern mobile touch slider and framework with hardware accelerated transitions

2 lines 2.71 kB
import{c as createShadow}from"../shared/create-shadow.min.mjs";import{e as effectInit}from"../shared/effect-init.min.mjs";import{e as effectTarget}from"../shared/effect-target.min.mjs";import{e as effectVirtualTransitionEnd}from"../shared/effect-virtual-transition-end.min.mjs";import{p as getSlideTransformEl,o as getRotateFix}from"../shared/utils.min.mjs";const EffectCreative=({swiper:e,extendParams:t,on:r})=>{function s(){return e.params.creativeEffect}t({creativeEffect:{limitProgress:1,shadowPerProgress:!1,progressMultiplier:1,perspective:!0,prev:{translate:[0,0,0],rotate:[0,0,0],opacity:1,scale:1},next:{translate:[0,0,0],rotate:[0,0,0],opacity:1,scale:1}}});const a=e=>"string"==typeof e?e:`${e}px`;effectInit({effect:"creative",swiper:e,on:r,setTranslate:()=>{const{slides:t,wrapperEl:r,slidesSizesGrid:i}=e,o=s(),{progressMultiplier:n}=o,l=e.params.centeredSlides,c=getRotateFix(e);if(l){const t=i[0]/2-(e.params.slidesOffsetBefore??0);r.style.transform=`translateX(calc(50% - ${t}px))`}for(let r=0;r<t.length;r+=1){const s=t[r],i=s.progress??0,f=Math.min(Math.max(i,-o.limitProgress),o.limitProgress);let m=f;l||(m=Math.min(Math.max(s.originalProgress??0,-o.limitProgress),o.limitProgress));const p=s.swiperSlideOffset??0,d=[e.params.cssMode?-p-e.translate:-p,0,0],g=[0,0,0];let h=!1;e.isHorizontal()||(d[1]=d[0],d[0]=0);let w={translate:[0,0,0],rotate:[0,0,0],scale:1,opacity:1};f<0?(w=o.next,h=!0):f>0&&(w=o.prev,h=!0),d.forEach((e,t)=>{d[t]=`calc(${e}px + (${a(w.translate[t])} * ${Math.abs(f*n)}))`}),g.forEach((e,t)=>{g[t]=w.rotate[t]*Math.abs(f*n)}),s.style.zIndex=String(-Math.abs(Math.round(i))+t.length);const y=d.join(", "),u=`rotateX(${c(g[0])}deg) rotateY(${c(g[1])}deg) rotateZ(${c(g[2])}deg)`,M=m<0?`scale(${1+(1-w.scale)*m*n})`:`scale(${1-(1-w.scale)*m*n})`,$=m<0?1+(1-w.opacity)*m*n:1-(1-w.opacity)*m*n,v=`translate3d(${y}) ${u} ${M}`;if(h&&w.shadow||!h){let e=s.querySelector(".swiper-slide-shadow");if(!e&&w.shadow&&(e=createShadow("creative",s)),e){const t=o.shadowPerProgress?f*(1/o.limitProgress):f;e.style.opacity=String(Math.min(Math.max(Math.abs(t),0),1))}}const E=effectTarget(o,s);E.style.transform=v,E.style.opacity=String($),w.origin&&(E.style.transformOrigin=w.origin)}},setTransition:t=>{const r=e.slides.map(e=>getSlideTransformEl(e));r.forEach(e=>{e.style.transitionDuration=`${t}ms`,e.querySelectorAll(".swiper-slide-shadow").forEach(e=>{e.style.transitionDuration=`${t}ms`})}),effectVirtualTransitionEnd({swiper:e,duration:t,transformElements:r,allSlides:!0})},perspective:()=>s().perspective,overwriteParams:()=>({watchSlidesProgress:!0,virtualTranslate:!e.params.cssMode})})};export{EffectCreative as default}; //# sourceMappingURL=effect-creative.min.mjs.map