-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotate-number.min.js
1 lines (1 loc) · 1.42 KB
/
rotate-number.min.js
1
!function(t){t.rotateNumber=function(e,i){var n,a=this;a.init=function(){n=t.extend({},t.rotateNumber.defaultOptions,i),a.createDigitElements(),a.initBaseStyles()},a.createDigitElements=function(){for(var t=0;t<n.digits;t++){var i=document.createElement("span");i.innerHTML="0 1 2 3 4 5 6 7 8 9",i.className="digit",e[0].appendChild(i),""!==n.separator&&n.digits>t+1&&1==(n.digits-t)%3&&e[0].appendChild(a.separator())}},a.separator=function(){var t=document.createElement("span");return t.innerHTML=n.separator,t.className="separator",t},a.initBaseStyles=function(){e[0].style.height=n.digitSize+"px",e[0].style.fontSize=n.digitSize+"px",e[0].style.lineHeight=n.digitSize+"px",e[0].style.textAlign="center",e[0].style.overflow="hidden",e.find(".digit, .separator").each(function(t,e){e.style.position="relative",e.style.display="block",e.style.cssFloat="left",e.style.top=0,e.style.transition="top "+n.rotateDuration+"s ease"})},a.setNumber=function(i){e.find(".digit").each(function(e,a){var r=Math.floor(i%Math.pow(10,n.digits-e)/Math.pow(10,n.digits-e-1));t(a).css("top",-r*n.digitSize)})},a.resizeDigit=function(t){n.digitSize=t,e[0].style.height=n.digitSize+"px",e[0].style.fontSize=n.digitSize+"px",e[0].style.lineHeight=n.digitSize+"px"},a.init()},t.rotateNumber.defaultOptions={digits:3,digitSize:50,rotateDuration:.6,separator:""},t.fn.rotateNumber=function(e){return Object.create(new t.rotateNumber(this,e))}}(window.Zepto||window.jQuery);