I cobbled this together last year and will be re-using it.
have fun
You'll find the precise day and time to edit at the bottom of the script, should you want to adjust it to a fair time before (which i suggest you do, since no sane merchant will be taking orders on chrimbo day)
have fun
HTML Code:
<html> <head> <script type="text/javascript"> /*********************************************** * Dynamic Countdown script- © Dynamic Drive (http://www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit http://www.dynamicdrive.com/ for this script and 100s more. ***********************************************/ function cdtime(container, targetdate){ if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.currentTime=new Date() this.targetdate=new Date(targetdate) this.timesup=false this.updateTime() } cdtime.prototype.updateTime=function(){ var thisobj=this this.currentTime.setSeconds(this.currentTime.getSeconds()+1) setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second } cdtime.prototype.displaycountdown=function(baseunit, functionref){ this.baseunit=baseunit this.formatresults=functionref this.showresults() } cdtime.prototype.showresults=function(){ var thisobj=this var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds if (timediff<0){ //if time is up this.timesup=true this.container.innerHTML=this.formatresults() return } var oneMinute=60 //minute unit in seconds var oneHour=60*60 //hour unit in seconds var oneDay=60*60*24 //day unit in seconds var dayfield=Math.floor(timediff/oneDay) var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour) var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute) var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute)) if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level hourfield=dayfield*24+hourfield dayfield="n/a" } else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level minutefield=dayfield*24*60+hourfield*60+minutefield dayfield=hourfield="n/a" } else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level var secondfield=timediff dayfield=hourfield=minutefield="n/a" } this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield) setTimeout(function(){thisobj.showresults()}, 1000) //update results every second } function formatresults(){ if (this.timesup==false){//if target date/time not yet met var displaystring=arguments[0]+" days "+arguments[1]+" hours "+arguments[2]+" minutes "+arguments[3]+" seconds left to order for the festive season!" } else{ //else if target date/time met var displaystring="You're too late. Christmas orders can no longer be accepted!" } return displaystring } </script></head> <body> <div style="font: normal 12px Tahoma;padding-left: 20px;padding-bottom: 4px;padding-right: 4px;padding-top: 4px;margin: 0px;background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIsSURBVDjLpVNLSJQBEP7+h6uu62vLVAJDW1KQTMrINQ1vPQzq1GOpa9EppGOHLh0kCEKL7JBEhVCHihAsESyJiE4FWShGRmauu7KYiv6Pma+DGoFrBQ7MzGFmPr5vmDFIYj1mr1WYfrHPovA9VVOqbC7e/1rS9ZlrAVDYHig5WB0oPtBI0TNrUiC5yhP9jeF4X8NPcWfopoY48XT39PjjXeF0vWkZqOjd7LJYrmGasHPCCJbHwhS9/F8M4s8baid764Xi0Ilfp5voorpJfn2wwx/r3l77TwZUvR+qajXVn8PnvocYfXYH6k2ioOaCpaIdf11ivDcayyiMVudsOYqFb60gARJYHG9DbqQFmSVNjaO3K2NpAeK90ZCqtgcrjkP9aUCXp0moetDFEeRXnYCKXhm+uTW0CkBFu4JlxzZkFlbASz4CQGQVBFeEwZm8geyiMuRVntzsL3oXV+YMkvjRsydC1U+lhwZsWXgHb+oWVAEzIwvzyVlk5igsi7DymmHlHsFQR50rjl+981Jy1Fw6Gu0ObTtnU+cgs28AKgDiy+Awpj5OACBAhZ/qh2HOo6i+NeA73jUAML4/qWux8mt6NjW1w599CS9xb0mSEqQBEDAtwqALUmBaG5FV3oYPnTHMjAwetlWksyByaukxQg2wQ9FlccaK/OXA3/uAEUDp3rNIDQ1ctSk6kHh1/jRFoaL4M4snEMeD73gQx4M4PsT1IZ5AfYH68tZY7zv/ApRMY9mnuVMvAAAAAElFTkSuQmCC);background-position: left center;background-repeat: no-repeat;background-color: #fffcd1;font-size: 11px;"> <!-- final order, countdown timer --> <span id="countdowncontainer"></span> <script type="text/javascript"> var futuredate=new cdtime("countdowncontainer", "December 25, 2009 12:00:00") futuredate.displaycountdown("days", formatresults) </script> <!-- /final order, countdown timer --> </div> </body> </html>
Comment