ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingเขียน code CountDown ปีใหม่ ยังไงดีหรอครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: เขียน code CountDown ปีใหม่ ยังไงดีหรอครับ  (อ่าน 2461 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
5live
Newbie
*

พลังน้ำใจ: 4
ออฟไลน์ ออฟไลน์

กระทู้: 40



ดูรายละเอียด
« เมื่อ: 27 ธันวาคม 2008, 12:31:32 »

ไม่รู้ว่าจะใช้ javascript หรือ php ดีอ่ะครับ  phpผมเขียนajaxไม่เป็นอ่ะครับ  Huh?
บันทึกการเข้า
alert
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 50
ออฟไลน์ ออฟไลน์

กระทู้: 1,741



ดูรายละเอียด
« ตอบ #1 เมื่อ: 27 ธันวาคม 2008, 13:44:59 »

โค๊ด:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>

 </HEAD>

 <BODY>
 <script language="JavaScript">
TargetDate = "1/1/2009 00:00 AM";
BackColor = "white";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "เหลือเวลาอีก %%D%% วัน, %%H%% ชั่วโมง, %%M%% นาที, %%S%% วินาที. ก็ปีใหม่แล้ว";
FinishMessage = "It is finally here!";


function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(secs) {
  if (secs < 0) {
    document.getElementById("cntdwn").innerHTML = FinishMessage;
    return;
  }
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  document.getElementById("cntdwn").innerHTML = DisplayStr;
  if (CountActive)
    setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
 document.write("<span id='cntdwn' style='background-color:" + backcolor +
                "; color:" + forecolor + "'></span>");
}

if (typeof(BackColor)=="undefined")
  BackColor = "white";
if (typeof(ForeColor)=="undefined")
  ForeColor= "black";
if (typeof(TargetDate)=="undefined")
  TargetDate = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat)=="undefined")
  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive)=="undefined")
  CountActive = true;
if (typeof(FinishMessage)=="undefined")
  FinishMessage = "";
if (typeof(CountStepper)!="number")
  CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
  LeadingZero = true;


CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
  CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);
var dnow = new Date();
if(CountStepper>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);

</script>

 </BODY>
</HTML>


ลองเอาไปดัดแปลงต่อดูนะครับ

ปล. ผมเอาของ เว็บนี้มาแก้ไขหน่ะครับ ให้ credit เค้าซะหน่อย
http://www.hashemian.com/tools/javascript-countdown.htm Smiley
« แก้ไขครั้งสุดท้าย: 27 ธันวาคม 2008, 13:48:22 โดย watchi » บันทึกการเข้า

***** รับซื้อเว็บไซต์สายขาวคุณภาพ  ตั้งแต่ 500-30,000 uip มี traffic มาจาก Google  และไม่เคยโดนแบน adsense  เสนอราคามาทาง pm ได้เลยครับ *****
หน้า: [1]   ขึ้นบน
พิมพ์