PHP+javascript液晶时钟

<?
  $size_small=5;//液晶宽度
  $size_big=25;//液晶长度
  $distance=10;//间距
  $color_back="#DDDDDD";
  $color_dark="#CCCCCC";
  $color_light="#000000";
  $number=0;
?>
<html>
<head>
<title>Timer</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<script language="javascript">
// *****************************************************************
//                   Written By Caocao
//                   caocao@eastday.com
//                   http://caocao.oso.com.cn
// *****************************************************************
function swapcolor(obj,onoff)//改变颜色
{
  if (onoff)
  {
    obj.style.background="<? echo $color_light;?>";
  }
  else
  {
    obj.style.background="<? echo $color_dark;?>";
  }
}

function change(number,timer)//处理数字显示
{
  switch (timer)
  {
    case 0:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),1);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),0);
      swapcolor(eval("time"+number+"4"),1);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),1);
      break;
    case 1:
      swapcolor(eval("time"+number+"0"),0);
      swapcolor(eval("time"+number+"1"),0);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),0);
      swapcolor(eval("time"+number+"4"),0);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),0);
      break;
    case 2:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),0);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),1);
      swapcolor(eval("time"+number+"5"),0);
      swapcolor(eval("time"+number+"6"),1);
      break;
    case 3:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),0);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),0);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),1);
      break;
    case 4:
      swapcolor(eval("time"+number+"0"),0);
      swapcolor(eval("time"+number+"1"),1);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),0);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),0);
      break;
    case 5:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),1);
      swapcolor(eval("time"+number+"2"),0);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),0);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),1);
      break;
    case 6:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),1);
      swapcolor(eval("time"+number+"2"),0);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),1);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),1);
      break;
    case 7:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),0);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),0);
      swapcolor(eval("time"+number+"4"),0);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),0);
      break;
    case 8:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),1);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),1);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),1);
      break;
    case 9:
      swapcolor(eval("time"+number+"0"),1);
      swapcolor(eval("time"+number+"1"),1);
      swapcolor(eval("time"+number+"2"),1);
      swapcolor(eval("time"+number+"3"),1);
      swapcolor(eval("time"+number+"4"),0);
      swapcolor(eval("time"+number+"5"),1);
      swapcolor(eval("time"+number+"6"),1);
      break;
  }
}

function show()//更新时间
{
  var now=new Date();
  change(0,Math.floor(now.getHours()/10));
  change(1,Math.floor(now.getHours()%10));
  change(2,Math.floor(now.getMinutes()/10));
  change(3,Math.floor(now.getMinutes()%10));
  change(4,Math.floor(now.getSeconds()/10));
  change(5,Math.floor(now.getSeconds()%10));
  setTimeout("show()",200);
}
</script>

</head>
<?
  echo "<body bgcolor=".$color_back.">";
  echo "<table width=".(($size_small*3+$size_big+$distance)*6)." border=0 cellspacing=0 cellpadding=0><tr>";
  for ($nunber=0;$number<6;$number++)
  {
    $recid=0;
    echo "<td><table width=".($size_small*2+$size_big)." border=0 cellspacing=0 cellpadding=0><tr>";
    echo "<td width=".$size_small." height=".$size_small."></td>";
    echo "<td width=".$size_big." height=".$size_small."><div id=time".$number.$recid++." style="position:relative; width:".$size_big."px; height:".$size_small."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "<td width=".$size_small." height=".$size_small."></td>";
    echo "</tr><tr>";
    echo "<td width=".$size_small." height=".$size_big."><div id=time".$number.$recid++." style="position:relative; width:".$size_small."px; height:".$size_big."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "<td width=".$size_big." height=".$size_big."></td>";
    echo "<td width=".$size_small." height=".$size_big."><div id=time".$number.$recid++." style="position:relative; width:".$size_small."px; height:".$size_big."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "</tr><tr>";
    echo "<td width=".$size_small." height=".$size_small."></td>";
    echo "<td width=".$size_big." height=".$size_small."><div id=time".$number.$recid++." style="position:relative; width:".$size_big."px; height:".$size_small."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "<td width=".$size_small." height=".$size_small."></td>";
    echo "</tr><tr>";
    echo "<td width=".$size_small." height=".$size_big."><div id=time".$number.$recid++." style="position:relative; width:".$size_small."px; height:".$size_big."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "<td width=".$size_big." height=".$size_big."></td>";
    echo "<td width=".$size_small." height=".$size_big."><div id=time".$number.$recid++." style="position:relative; width:".$size_small."px; height:".$size_big."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "</tr><tr>";
    echo "<td width=".$size_small." height=".$size_small."></td>";
    echo "<td width=".$size_big." height=".$size_small."><div id=time".$number.$recid++." style="position:relative; width:".$size_big."px; height:".$size_small."px; background:".$color_dark."; font-size:1px"></div></td>";
    echo "<td width=".$size_small." height=".$size_small."></td>";
    echo "</tr></table></td>";
    if ($number==1||$number==3)
    {
      echo "<td><table width=".($size_small*3)." border=0 cellspacing=0 cellpadding=0><tr>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "</tr><tr>";
      echo "<td width=".$size_small." height=".$size_big."></td>";
      echo "<td width=".$size_small." height=".$size_big."><div style="position:relative; width:".$size_small."px; height:".$size_small."px; background:".$color_light."; font-size:1px"></div></td>";
      echo "<td width=".$size_small." height=".$size_big."></td>";
      echo "</tr><tr>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "</tr><tr>";
      echo "<td width=".$size_small." height=".$size_big."></td>";
      echo "<td width=".$size_small." height=".$size_big."><div style="position:relative; width:".$size_small."px; height:".$size_small."px; background:".$color_light."; font-size:1px"></div></td>";
      echo "<td width=".$size_small." height=".$size_big."></td>";
      echo "</tr><tr>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "<td width=".$size_small." height=".$size_small."></td>";
      echo "</tr></table></td>";
    }
  }
  echo "</tr></table>";
?>
<script language="javascript">
  show();
</script>
</body>
</html>

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】

(0)

相关推荐

  • PHP+javascript液晶时钟

    <?   $size_small=5;//液晶宽度   $size_big=25;//液晶长度   $distance=10;//间距   $color_back="#DDDDDD";   $color_dark="#CCCCCC";   $color_light="#000000";   $number=0; ?> <html> <head> <title>Timer</title>

  • js+html5实现canvas绘制网页时钟的方法

    本文实例讲述了js+html5实现canvas绘制网页时钟的方法,画的是一个可用于网页的.带摆的钟表,可以通过按钮调整其大小和位置,具体实现内容如下 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Clock</title> <script type="tex

  • js Canvas实现的日历时钟案例分享

    Html: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script src="requestNextAnimationFrame.js"></script> <script src="calendarWithTime.js">&

  • 基于jQuery和CSS3制作数字时钟附源码下载(jquery篇)

    废话不多说了,先给大家展示下效果图,感兴趣的朋友继续往下看 哦 查看演示       源码下载 HTML 和上一篇文章:使用jQuery和CSS3制作数字时钟(CSS3篇)一样的HTML结构,只是多了个>date用来展示日期和星期的. <div id="clock" class="light"> <div class="display"> <div class="date"></

  • JavaScript实现简单的时钟实例代码

    复制代码 代码如下: <html> <head> <title>JS实现简单的时钟</title><script> function displayTime() {        document.getElementById("time").innerHTML = new Date().toTimeString();    } setInterval(displayTime,1000);      // 每隔1秒钟调用dis

  • JavaScript电子时钟倒计时

    本文实例讲解了JavaScript电子时钟倒计时的详细代码,分享给大家供大家参考,具体内容如下 JavaScript时间类 1.获取时分秒:          getHours()          getMinutes();          getSeconds(); 2.获取年月日:          getFullYear();          getMonth() + 1;//获取的月份需要+1:          getDate(); //日期          getDay();

  • javascript结合Canvas 实现简易的圆形时钟

    之前学习了下html5中的canvas元素,为了练练手就实现了一个简易的时钟.时钟本身并不复杂,也没有使用图片进行美化,不过麻雀虽小五脏俱全,下面就与大家分享一下: 演示效果: html代码: 复制代码 代码如下: <!DOCTYPE html> <html> <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  • JavaScript之创意时钟项目(实例讲解)

    "时钟展示项目"说明文档(文档尾部附有相应代码) 一.最终效果展示: 二.项目亮点 1.代码结构清晰明了 2.可以实时动态显示当前时间与当前日期 3.界面简洁.美观.大方 4.提高浏览器兼容性 三.知识点汇总: jQuery.原生javascript.css3.h5 四.重难点解释 1.各个指针的旋转角度的获取 首先要明确如下概念: 时钟指针旋转一周360度 时针: 表盘上共有12小时,每经过一小时,要旋转30度: 分针: 表盘上共有60个小格子,分针每走一分钟,经过一个小格子,转动6

  • Android多功能时钟开发案例(基础篇)

    本文我们进入Android多功能时钟开发实战学习,具体的效果可以参考手机上的时钟,内容如下 首先我们来看一看布局文件layout_main.xml 整个布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="match_parent" androi

  • Java编程小实例—数字时钟的实现代码示例

    本文的实例是Java编程实现一个数字时钟,代码测试可用,练练手吧.代码如下: package me.socketthread; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.util.Calendar; import java.util.GregorianCalenda

随机推荐