Last active
November 6, 2016 16:10
-
-
Save kannans/e8d205df9992d2f8fec14299f8743c10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CSS | |
.jst-hours { | |
float: left; | |
} | |
.jst-minutes { | |
float: left; | |
} | |
.jst-seconds { | |
float: left; | |
} | |
.jst-clearDiv { | |
clear: both; | |
} | |
.jst-timeout { | |
color: red; | |
} | |
Date.prototype.addSeconds= function(h){ | |
this.setSeconds(this.getSeconds()+h); | |
return this; | |
} | |
var date = new Date().addSeconds(5) / 1000 | |
$('.timer2').countid({ | |
clock: true, | |
dateTplElapsed: "%H:%M:%S", | |
complete: function( el ){ | |
el.animate({ 'font-size': '50px'}) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(e,t,n,i){function a(t,n){this.elem=t,this.$elem=e(t),this.$elem_original=this.$elem,this.options=n,this.metadata=this.$elem.data(),this._init()}t.cancelRequestAnimFrame=function(){return t.cancelAnimationFrame||t.webkitCancelRequestAnimationFrame||t.mozCancelRequestAnimationFrame||t.oCancelRequestAnimationFrame||t.msCancelRequestAnimationFrame||clearTimeout}(),t.requestAnimFrame=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e,n){return t.setTimeout(e,1e3/60)}}();var o="countid";a.prototype={defaults:{start:0,end:0,speed:10,tick:10,clock:!1,switchClock:!0,dateTime:"%m/%d/%y %h:%i:%s",dateTplRemaining:"Remaining time: %D days and %H:%M:%S ",dateTplElapsed:"Elapsed time: %D days and %H:%M:%S ",format:!1,complete:!1},lang:{textSelectAll:function(){return"Select all"}},_init:function(){this.config=e.extend({},this.defaults,this.options,this.metadata);var t=this;t.id=t._getRandomInt(999,99999),t.timer={},t.isPaused=!1,t.speed=t.config.speed,t.tick=t.config.tick,t.clock=t.config.clock,t.dateTpl=t.config.dateTplRemaining,0===t.config.start&&0===t.config.end&&(t.config.end=1*t.$elem.text()),t.request=0,t.paused=!1,t._setSteps(t.config.start,t.config.end),t.clock&&(isNaN(t.config.dateTime)||(t.config.dateTime=new Date(1e3*t.config.dateTime)),t._setClock()),"function"==typeof t.$elem.waypoint?t.$elem.waypoint(function(){t._loop()},{offset:"100%",triggerOnce:!0}):t._loop()},_setTime:function(){var e=this,t=Date.now(),n=new Date(e.config.dateTime).getTime(),i=1*Math.floor(t/1),a=1*(n/1),o=Math.abs(i-a),c=0;return i>a?c=1e16:o=a-i+1e3,e.step=Math.floor(o/1e3)+1,[o,c]},_setClock:function(){function e(e,t){var n=t-e.toString().length+1;return Array(+(n>0&&n)).join("0")+e}function t(t,a){var o=Math.floor(n.secLeft/i[t]),c=y[t]>0?e(o,y[t]):o;n.thisTpl=n.thisTpl.replace("%"+t,c),n.secLeft=n.secLeft-o*i[t]}var n=this,i={Y:31536e6,O:2629739520,W:6048e5,D:864e5,H:36e5,M:6e4,S:1e3,U:1},a=new Date(n.config.dateTime).getTime();if(isNaN(a)){var o=new Date,c=o.getMonth()+1,s=o.getDate(),r=o.getFullYear(),f=o.getHours(),m=o.getMinutes(),u=o.getSeconds();n.config.dateTime=n.config.dateTime.replace("%m",c),n.config.dateTime=n.config.dateTime.replace("%d",s),n.config.dateTime=n.config.dateTime.replace("%y",r),n.config.dateTime=n.config.dateTime.replace("%h",f),n.config.dateTime=n.config.dateTime.replace("%i",m),n.config.dateTime=n.config.dateTime.replace("%s",u);var l=new Date(n.config.dateTime).getTime();isNaN(l)&&(n.config.dateTime="1/1/1970")}!n.config.dateTime,n.speed=1e3,n.tick=1;var d=n._setTime();n._setSteps(d[0],d[1]),d[0]<d[1]&&(n.dateTpl=n.config.dateTplElapsed);var p=n.dateTpl,g=-1!==p.search("%Y")?!0:!1,h=-1!==p.search("%O")?!0:!1,T=-1!==p.search("%W")?!0:!1,_=-1!==p.search("%D")?!0:!1,v=-1!==p.search("%H")?!0:!1,q=-1!==p.search("%M")?!0:!1,k=-1!==p.search("%S")?!0:!1,A=-1!==p.search("%U")?!0:!1;n.secLeft=!1;var i={Y:31536e6,O:2629739520,W:6048e5,D:864e5,H:36e5,M:6e4,S:1e3,U:1},y={Y:0,O:0,W:0,D:0,H:2,M:2,S:2,U:3};n.config.format=function(e){var i=n._setTime(),a=i[0];0==e&&(a=0),n.secLeft=a,n.thisTpl=p;return g?t("Y"):"",h?t("O"):"",T?t("W"):"",_?t("D"):"",v?t("H"):"",q?t("M"):"",k?t("S"):"",A?t("U"):"",n.thisTpl}},_setSteps:function(e,t){var n=this;n.start=1*e,n.end=1*t,n.current=n.start,n.clock||n.$elem.html(n.start),n.step=1*(Math.abs(n.current-n.end)/n.tick),n.dir=n.current>n.end?-1:1,n.tick=n.dir*n.tick},_rep:function(){var e=this;if(e.step>0){var t=e.current;"function"==typeof e.config.format&&(t=e.config.format(t)),e.$elem.html(t),e.step-=1,e.current+=e.tick}else{cancelRequestAnimFrame(e.request);var n=e.end;e.clock&&(e.config.switchClock?(e._setClock(),e._loop()):n=0),"function"==typeof e.config.format&&(n=e.config.format(n)),e.$elem.html(n),"function"==typeof e.config.complete&&e.config.complete(e.$elem)}},_loop:function(e,t){function n(){f.request=requestAnimFrame(n),f.frames++,c=Date.now(),r=c-s,r>a&&(s=c-r%a,f._rep())}var i,a,o,c,s,r,f=this;i=f.speed,a=1e3/i,s=Date.now(),o=s,f.frames=0,n()},_getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e},_eventCallback:function(e){var t=this;"function"==typeof t.config[e]},_initEvents:function(){},setCurrent:function(e){var t=this;e=1*e,1==t.dir&&(t.start>e||t.end<e)||-1==t.dir&&(t.start<e||t.end>e)||(t.current=e,t._setSteps(t.current,t.config.end),cancelRequestAnimFrame(t.request),t._loop())},toggleDir:function(){var e=this;cancelRequestAnimFrame(e.request),e._setSteps(e.end,e.start),e._loop()},togglePause:function(){var e=this;e.isPaused?e.unpause():e.pause()},pause:function(){var e=this;cancelRequestAnimFrame(e.request),e.isPaused=!0},unpause:function(){var e=this;e.isPaused=!1,cancelRequestAnimFrame(e.request),e._loop()},refresh:function(){var e=this;cancelRequestAnimFrame(e.request),e._setSteps(e.config.start,e.config.end),e._loop()}},e.fn[o]=function(t){var n=arguments;if(t===i||"object"==typeof t)return this.each(function(){e.data(this,"plugin_"+o)||e.data(this,"plugin_"+o,new a(this,t))});if("string"==typeof t&&"_"!==t[0]&&"init"!==t){var c;return this.each(function(){var i=e.data(this,"plugin_"+o);i instanceof a&&"function"==typeof i[t]&&(c=i[t].apply(i,Array.prototype.slice.call(n,1))),"destroy"===t&&e.data(this,"plugin_"+o,null)}),c!==i?c:this}}}(jQuery,window,document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment