js圣诞节倒计时网页

在线预览:http://keleyi.com/keleyi/phtml/jstexiao/17.htm

以下是代码:

  1 <!DOCTYPE html>
  2 <html xmlns="http://www.w3.org/1999/xhtml">
  3 <head>
  4 <title>javascript节日倒计时-柯乐义</title>
  5 <style type="text/css">
  6 .keleyilcd {
  7 background-color: black;
  8 color: yellow;
  9 font: bold 18px MS Sans Serif;
 10 padding: 3px;
 11 }
 12
 13 .keleyilcd sup {
 14 font-size: 80%;
 15 }
 16 </style>
 17 <script type="text/javascript">
 18 function cdtime(container, targetdate) {
 19 if (!document.getElementById || !document.getElementById(container)) return
 20 this.container = document.getElementById(container)
 21 this.currentTime = new Date()
 22 this.targetdate = new Date(targetdate)
 23 this.timesup = false
 24 this.updateTime()
 25 }
 26 cdtime.prototype.updateTime = function () {
 27 var thisobj = this
 28 this.currentTime.setSeconds(this.currentTime.getSeconds() + 1)
 29 setTimeout(function () { thisobj.updateTime() }, 1000) //update time every second
 30 }
 31 cdtime.prototype.displaycountdown = function (baseunit, functionref) {
 32 this.baseunit = baseunit
 33 this.formatresults = functionref
 34 this.showresults()
 35 }
 36 cdtime.prototype.showresults = function () {
 37 var thisobj = this
 38 var timediff = (this.targetdate - this.currentTime) / 1000
 39 if (timediff < 0) { //if time is up keleyi.com
 40 this.timesup = true
 41 this.container.innerHTML = this.formatresults()
 42 return
 43 }
 44 var oneMinute = 60
 45 var oneHour = 60 * 60
 46 var oneDay = 60 * 60 * 24
 47 var dayfield = Math.floor(timediff / oneDay)
 48 var hourfield = Math.floor((timediff - dayfield * oneDay) / oneHour)
 49 var minutefield = Math.floor((timediff - dayfield * oneDay - hourfield * oneHour) / oneMinute)
 50 var secondfield = Math.floor((timediff - dayfield * oneDay - hourfield * oneHour - minutefield * oneMinute))
 51 if (this.baseunit == "hours") {
 52 hourfield = dayfield * 24 + hourfield
 53 dayfield = "n/a"
 54 }
 55 else if (this.baseunit == "minutes") {
 56 minutefield = dayfield * 24 * 60 + hourfield * 60 + minutefield
 57 dayfield = hourfield = "n/a"
 58 }
 59 else if (this.baseunit == "seconds") {
 60 var secondfield = timediff
 61 dayfield = hourfield = minutefield = "n/a"
 62 }
 63 this.container.innerHTML = this.formatresults(dayfield, hourfield, minutefield, secondfield)
 64 setTimeout(function () { thisobj.showresults() }, 1000) //update results every second
 65 }
 66 function formatresults() {
 67 if (this.timesup == false) {
 68 var displaystring = arguments[0] + " days " + arguments[1] + " hours " + arguments[2] + " minutes " + arguments[3] + " seconds left"
 69 }
 70 else {
 71 var displaystring = "倒计时:"
 72 }
 73 return displaystring
 74 }
 75 function formatresults2() {
 76 if (this.timesup == false) {
 77 var displaystring = " 到圣诞节还有<span class=‘kel"+"eyilcd‘>" + arguments[0] + " <sup>天</sup> " + arguments[1] + " <sup>时</sup> " + arguments[2] + " <sup>分</sup> " + arguments[3] + " <sup>秒</sup></span>"
 78 }
 79 else {
 80 var displaystring = ""
 81 alert("Christmas is here!")
 82 }
 83 return displaystring
 84 }
 85 </script>
 86 </head>
 87 <body>
 88 <div id="countdowncontainer"></div>
 89 <br />
 90 <div id="countdowncontainer2"></div>
 91 <script type="text/javascript">
 92 var futuredate = new cdtime("countdowncontainer", "December 25, 2013 00:00:00")
 93 futuredate.displaycountdown("days", formatresults)
 94 var currentyear=new Date().getFullYear()
 95 var thischristmasyear=(new Date().getMonth()>=11 && new Date().getDate()>25)? currentyear+1 : currentyear
 96 var christmas=new cdtime("countdowncontainer2", "December 25, "+thischristmasyear+" 0:0:00")
 97 christmas.displaycountdown("days", formatresults2)
 98 </script>
 99 <div>
100 <p>来源:<a href="http://keleyi.com/a/bjad/3s0khhpt.htm">原文</a> <a href="http://keleyi.com">首页</a> <a href="http://keleyi.com/keleyi/phtml/">特效库</a> <a href="http://keleyi.com/a/bjac/iqiiedy2.htm">圣诞快乐</a></p>
101 </div>
102 </body>
103 </html>

web前端:http://www.cnblogs.com/jihua/p/webfront.html

时间: 2024-10-21 08:57:49

js圣诞节倒计时网页的相关文章

2014年圣诞节倒计时网页

2014年的圣诞节即将来临之季.爱编程小编给大家分享一款2014年圣诞节倒计时网页,当天的日期卡片有抖动的效果.一起看下效果图: 在线预览   源码下载 实现的代码. html代码: <h1> Merry Christmas</h1> <ul> <li> <div class="door"> 1</div> </li> <li> <div class="door"&

JS实现倒计时网页自动跳转(如404页面经常使用到的)

在web前端设计中,我们经常会遇到需要实现页面倒计时跳转的功能,例如在404页面中也会经常使用到此功能,那么如何实现呢,其实实现方法很简单,实现代码如下:<title>JS倒计时网页自动跳转代码</title> <script language="JavaScript" type="text/javascript"> function delayURL(url) { var delay = document.getElementB

JS倒计时网页自动跳转代码

<title>JS倒计时网页自动跳转代码</title> <script language="JavaScript" type="text/javascript"> function delayURL(url) { var delay = document.getElementById("time").innerHTML; if(delay > 0) { delay--; document.getElem

一个简单的js实现倒计时函数

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> <head> <met

js实现倒计时及时间对象

JS实现倒计时效果代码如下: 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>无标题文档</title>h 6 <style> 7 #box { 8 width: 100%; 9 height: 400px; 10 background: black; 11 color: #fff; 12 font-size:4

CSS+js打造的网页版俄罗斯方块游戏

<HTML> <SCRIPT> parent.moveTo((screen.width-775)/2,(screen.height-540)/2); parent.resizeTo(775,540) </SCRIPT> <HEAD> <META NAME="Title" CONTENT="JScript Simple Tetris"> <TITLE>CSS+js打造的网页版俄罗斯方块游戏丨石家庄

js实现倒计时60秒的简单代码(推荐)

<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js实现倒计时60秒的简单代码(推荐)</title> <script type="text/javascript"

JS时间倒计时

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf8" /><title>JS时间倒计时</title><script type="text/javascript">var time_

用JS实现倒计时(日期字符串作为参数)

<!doctype html> <html> <head> <meta charset="utf-8"> <title>JS实现倒计时</title> <style> *{ margin:0; padding:0; list-style:none;} body{ font-size:18px; text-align:center;} .time{ height:30px; padding:200px;}