javascript - JS Countdown timer for website counts from opening of page -


i'm working on html file, , working on countdown timer in middle of page counts down until site released.

screenshot: http://image.prntscr.com/image/4fd8693f6df14261aacb8333ee4a4859.png (i linked because it's on 2mb)

                var targetdate = new date().gettime() + 2592000000 //time in milliseconds, in case it's 1 month.                      slidechanges = [                                 { days:0, hours:0, minutes:0, seconds:6, slide:2},                                 { days:0, hours:0, minutes:0, seconds:0, slide:3}                                     ],                 quickjump = 10000,                 api = revapi432;              !function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery"],t):t(jquery)}(function(t){"use strict";function e(t){if(t instanceof date)return t;if(string(t).match(o))return string(t).match(/^[0-9]*$/)&&(t=number(t)),string(t).match(/\-/)&&(t=string(t).replace(/\-/g,"/")),new date(t);throw new error("couldn't cast `"+t+"` date object.")}function s(t){var e=t.tostring().replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");return new regexp(e)}function n(t){return function(e){var n=e.match(/%(-|!)?[a-z]{1}(:[^;]+;)?/gi);if(n)for(var a=0,o=n.length;o>a;++a){var r=n[a].match(/%(-|!)?([a-za-z]{1})(:[^;]+;)?/),l=s(r[0]),c=r[1]||"",u=r[3]||"",f=null;r=r[2],h.hasownproperty(r)&&(f=h[r],f=number(t[f])),null!==f&&("!"===c&&(f=i(u,f)),""===c&&10>f&&(f="0"+f.tostring()),e=e.replace(l,f.tostring()))}return e=e.replace(/%%/,"%")}}function i(t,e){var s="s",n="";return t&&(t=t.replace(/(:|;|\s)/gi,"").split(/\,/),1===t.length?s=t[0]:(n=t[0],s=t[1])),1===math.abs(e)?n:s}var a=[],o=[],r={precision:100,elapse:!1};o.push(/^[0-9]*$/.source),o.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),o.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),o=new regexp(o.join("|"));var h={y:"years",m:"months",n:"daystomonth",w:"weeks",d:"daystoweek",d:"totaldays",h:"hours",m:"minutes",s:"seconds"},l=function(e,s,n){this.el=e,this.$el=t(e),this.interval=null,this.offset={},this.options=t.extend({},r),this.instancenumber=a.length,a.push(this),this.$el.data("countdown-instance",this.instancenumber),n&&("function"==typeof n?(this.$el.on("update.countdown",n),this.$el.on("stoped.countdown",n),this.$el.on("finish.countdown",n)):this.options=t.extend({},r,n)),this.setfinaldate(s),this.start()};t.extend(l.prototype,{start:function(){null!==this.interval&&clearinterval(this.interval);var t=this;this.update(),this.interval=setinterval(function(){t.update.call(t)},this.options.precision)},stop:function(){clearinterval(this.interval),this.interval=null,this.dispatchevent("stoped")},toggle:function(){this.interval?this.stop():this.start()},pause:function(){this.stop()},resume:function(){this.start()},remove:function(){this.stop.call(this),a[this.instancenumber]=null,delete this.$el.data().countdowninstance},setfinaldate:function(t){this.finaldate=e(t)},update:function(){if(0===this.$el.closest("html").length)return void this.remove();var e,s=void 0!==t._data(this.el,"events"),n=new date;e=this.finaldate.gettime()-n.gettime(),e=math.ceil(e/1e3),e=!this.options.elapse&&0>e?0:math.abs(e),this.totalsecsleft!==e&&s&&(this.totalsecsleft=e,this.elapsed=n>=this.finaldate,this.offset={seconds:this.totalsecsleft%60,minutes:math.floor(this.totalsecsleft/60)%60,hours:math.floor(this.totalsecsleft/60/60)%24,days:math.floor(this.totalsecsleft/60/60/24)%7,daystoweek:math.floor(this.totalsecsleft/60/60/24)%7,daystomonth:math.floor(this.totalsecsleft/60/60/24%30.4368),totaldays:math.floor(this.totalsecsleft/60/60/24),weeks:math.floor(this.totalsecsleft/60/60/24/7),months:math.floor(this.totalsecsleft/60/60/24/30.4368),years:math.abs(this.finaldate.getfullyear()-n.getfullyear())},this.options.elapse||0!==this.totalsecsleft?this.dispatchevent("update"):(this.stop(),this.dispatchevent("finish")))},dispatchevent:function(e){var s=t.event(e+".countdown");s.finaldate=this.finaldate,s.elapsed=this.elapsed,s.offset=t.extend({},this.offset),s.strftime=n(this.offset),this.$el.trigger(s)}}),t.fn.countdown=function(){var e=array.prototype.slice.call(arguments,0);return this.each(function(){var s=t(this).data("countdown-instance");if(void 0!==s){var n=a[s],i=e[0];l.prototype.hasownproperty(i)?n[i].apply(n,e.slice(1)):null===string(i).match(/^[$a-z_][0-9a-z_$]*$/i)?(n.setfinaldate.call(n,i),n.start()):t.error("method %s not exist on jquery.countdown".replace(/\%s/gi,i))}else new l(this,e[0],e[1])})}});               var currentd,currenth,currentm,currents;              function animateandupdate(o,nt,ot) {                if (ot==undefined) {                  o.html(nt);                } else {                   if (o.css("opacity")>0) {                   punchgs.tweenlite.fromto(o,0.45,                     {autoalpha:1,rotationy:0,scale:1},                     {autoalpha:0,rotationy:-180,scale:0.5,ease:punchgs.back.easein,oncomplete:function() { o.html(nt);} });                punchgs.tweenlite.fromto(o,0.45,                     {autoalpha:0,rotationy:180,scale:0.5},                     {autoalpha:1,rotationy:0,scale:1,ease:punchgs.back.easeout,delay:0.5 });                   } else {                      o.html(nt);                   }                }               return nt;             }              function countprocess(event) {                var newd = event.strftime('%d'),                   newh = event.strftime('%h'),                   newm = event.strftime('%m'),                   news = event.strftime('%s');               if (newd != currentd) currentd = animateandupdate(jquery('#c_days'),newd,currentd);               if (newh != currenth) currenth = animateandupdate(jquery('#c_hours'),newh,currenth);               if (newm != currentm) currentm = animateandupdate(jquery('#c_minutes'),newm,currentm);               if (news != currents) currents = animateandupdate(jquery('#c_seconds'),news,currents);                jquery.each(slidechanges,function(i,obj) {                 var dr = obj.days==undefined || obj.days>=newd,                     hr = obj.hours==undefined || obj.hours>=newh,                     mr = obj.minutes==undefined || obj.minutes>=newm,                     sr = obj.seconds==undefined || obj.seconds>=news;                   if (dr && hr && mr && sr && !obj.changedown) {                      api.revshowslide(obj.slide);                      obj.changedown = true;                   }               })             }              jquery('#skipahead').click(function(){               var smalloffset = new date().gettime() + quickjump;              api.countdown(smalloffset,countprocess);             });              api.countdown(targetdate, countprocess);         }     }); /*ready*/ 

now issue here is, counter starts counting down 30 days when page gets loaded. there way first string (since that's issue here think) act custom date setting can choose when starts counting, or better if possible counts point?

the page close bound code, wrong value stops page loading @ , counter handles various events on page, which, keep.

the countdown.js jquery engine made hilios. page of code at: https://github.com/hilios/jquery.countdown

thanks get,

frozen snow

change following line:

var targetdate = new date().gettime() + 2592000000

to this:

var targetdate = new date(2016, 7, 1, 5, 30, 0) // change values correspond date want

this set target date monday august 1st, @ 5:30.

look @ https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date more info on creating dates.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -