-
Notifications
You must be signed in to change notification settings - Fork 1
/
skdcarousel.min.js
1 lines (1 loc) · 1.98 KB
/
skdcarousel.min.js
1
!function(t){t.SKDCarousel=function(t){var e=0,o=0,n=this;this.onCenterFn=function(){};var s=t||{selector:"skd-carousel",delay:5},l=document.getElementById(s.selector);if(l){var r=1e3*parseInt(s.delay)||3e3,h=125,a=.6,c=.7,u=.8,f=l.querySelectorAll("img");f=Array.prototype.slice.call(f);var d=[],p=l.clientWidth,y=l.clientHeight,g=Math.floor(f.length/2);this.setTimer=function(){o++,o==f.length&&(o=0),e=setTimeout(function(){n.play(f[o])},r)},this.init=function(){var t,e,o,l,r,m,w;for(t=s.width?s.width:f[0].clientWidth,e=s.height?s.height:f[0].clientHeight,o=1,l=Math.round(p/2)-Math.round(t/2),r=Math.round(y/2)-Math.round(e/2),d[g]={w:t,h:e,o:o,l:l,t:r,z:g,i:0},w=h,m=g,i=g+1;i<f.length;i++)w*=a,t=c*d[i-1].w,e=c*d[i-1].h,o=u*d[i-1].o,l=d[i-1].l+d[i-1].w+w-t,--m,r=Math.round(y/2)-Math.round(e/2),d[i]={w:t,h:e,o:o,l:l,t:r,z:m,i:i};for(w=h,m=g,i=g-1;i>=0;i--)w*=a,t=c*d[i+1].w,e=c*d[i+1].h,o=u*d[i+1].o,l=d[i+1].l-w,--m,r=Math.round(y/2)-Math.round(e/2),d[i]={w:t,h:e,o:o,l:l,t:r,z:m,i:i};for(i=0;i<f.length;i++)f[i].orgPos=i,f[i].crslPos=i,f[i].addEventListener("click",function(i){this.crslPos!=g&&(n.play(this),n.onCenterFn.call(null,this.orgPos))})},this.play=function(i){this.moveItem(i),this.setItemPosition(),s.auto&&this.setTimer()},this.moveItem=function(t){for(var e,o=t.crslPos<g?"forward":"backward";t.crslPos!=g;)for("forward"==o?(e=f.pop(),f.unshift(e)):(e=f.shift(),f.push(e)),i=0;i<f.length;i++)f[i].crslPos=i,f[i].className="";t.className="active"},this.setItemPosition=function(){for(i=0;i<f.length;i++)f[i].style.width=d[i].w+"px",f[i].style.height=d[i].h+"px",f[i].style.opacity=d[i].o,f[i].style.left=d[i].l+"px",f[i].style.top=d[i].t+"px",f[i].style.zIndex=d[i].z,d[i].i=i},this.findMappedItem=function(t){for(i=0;i<f.length;i++)if(t==f[i].orgPos)return f[i]},f[0].src=f[0].src,f[0].addEventListener("load",function(){n.init(),n.play(f[0]),setTimeout(function(){l.style.visibility="visible"},800)})}},SKDCarousel.prototype.onCenter=function(i){"function"==typeof i&&(this.onCenterFn=i)}}(window);