成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? jQuery+css實現(xiàn)的時鐘效果(兼容各瀏覽器)
全站頭部文字 我要出現(xiàn)在這里
jQuery+css實現(xiàn)的時鐘效果(兼容各瀏覽器) 744 2024-03-12   

本文實例講述了jQuery+css實現(xiàn)的時鐘效果。分享給大家供大家參考,具體如下:

運行效果截圖如下:

查看圖片

這里沒有做太多的修飾,簡單的實現(xiàn)了一下功能,另外,用的是js的setTimeout方法,當(dāng)時間長了之后,會有一定的延時,建議,在每隔多少分鐘執(zhí)行一次時鐘校準(zhǔn)!哈哈,都有誤差的嘛,反正我是沒給你校。

具體代碼如下:

<!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">
<head>
  <title></title>
  <script src="http://www.gimoo.net/t/1903/jquery-1.7.1.min.js" type="text/javascript"></script>
  <script type="text/javascript" >
    var addRadian = Math.PI / 30;
    var wrapper = null;
    var minutes = 0;
    var hours = 0;
    var secondsLineLength = 14;
    var secondLineLength = 20;
    function cloneObj(obj1) {
      var tempObj = {};
      for (var i in obj1) {
        if (obj1.hasOwnProperty(i)) {
          tempObj[i] = obj1[i];
        }
      }
      return tempObj;
    }
    function createMinute(po, r, text) {
      var minute = [];
      minute.push('<div class="minute" style="left:');
      minute.push(po.x);
      minute.push('px; top:');
      minute.push(po.y);
      minute.push('px;" >');
      minute.push(text);
      minute.push('</div>');
      wrapper.append(minute.join(''));
    }
    function createHour(po, r, text) {
      var minute = [];
      minute.push('<div class="hour" style="left:');
      minute.push(po.x);
      minute.push('px; top:');
      minute.push(po.y);
      minute.push('px;" >');
      minute.push(text);
      minute.push('</div>');
      wrapper.append(minute.join(''));
    }
    function initSeconds(text, center, range) {
      var now_seconds = new Date().getSeconds();
      now_seconds = now_seconds > 0 ? now_seconds - 1 : 0;
      for (var i = 0; i < secondsLineLength + 1; i++) {
        createFlower(center, '●', range, (i + 1) * secondLineLength, Math.PI / 2 + (now_seconds) * addRadian, true, i == secondsLineLength ? true : false);
      }
    }
    function initMinutes(r, text, center) {
      var x = 0,
        y = 0;
      for (var i = 0; i < 60; i++) {
        x = center.x - Math.cos(Math.PI / 2 + i * addRadian) * (r + secondLineLength);
        y = center.y - Math.sin(Math.PI / 2 + i * addRadian) * (r + secondLineLength); 
        createMinute({x: x,y: y}, r, text);
      }
      minutes = new Date().getMinutes();
      waldedMinute(minutes);
    }
    function initHours(r, text, center) {
      var x = 0,
        y = 0;
      for (var i = 0; i < 60; i+=5) {
        x = center.x - Math.cos(Math.PI / 2 + i * addRadian) * (r + secondLineLength);
        y = center.y - Math.sin(Math.PI / 2 + i * addRadian) * (r + secondLineLength);
        createHour({ x: x, y: y }, r, text);
      }
      hours = new Date().getHours();
      waldedHour(hours);
    }
    function waldedMinute(index) {
      var index = Math.floor((index % 60)) > 0 ? Math.floor((index % 60)) + 1 : 0;
      wrapper.find(".minute:lt(" + index + ")").css('color', "green");
      if (index > 0) {
        wrapper.find(".minute:eq(0)").css('color', '#DDDDDD');
      }
    }
    function waldedHour(index) {
      var index = Math.floor((index%12)) > 0 ? Math.floor((index%12)) + 1:0;
      wrapper.find(".hour:lt(" + index + ")").css('color', "green");
      if(index > 0) {
        wrapper.find(".hour:eq(0)").css('color', '#494949');
      }
    }
    function animation(obj, r, radian, range, center, text, last) {
      logNowTime();
      radian += addRadian;
      var x = center.x - Math.cos(radian) * r;
      var y = center.y - Math.sin(radian) * r;
      obj.css({ "left": x, "top": y });
      if (last && radian > Math.PI * 5 / 2 - 0.1) {
        radian = Math.PI / 2;
        minutes++;
        if (minutes < 60) {
        } else {
          if (minutes % 60 == 0) {
            hours++;
            if (hours % 12 != 0) {
            } else {
              wrapper.find(".hour").css('color', "#494949");
            }
            waldedHour(hours);
          } else {
            wrapper.find(".minute").css('color', "#DDDDDD");   
          }
        }
        waldedMinute(minutes); 
      }
      setTimeout(function () {
        animation(obj, r, radian, range, center, text, last);
      }, 1000);
    }
    function createFlower(center, text, range, r, radian, autoAnimate, last) {
      var flower = [];
      flower.push('<div class="second"');
      flower.push(' style="left:');
      flower.push(center.x);
      flower.push('px; top:');
      flower.push(center.y);
      flower.push('px;');
      flower.push(autoAnimate ? '" >' : 'color:red;" >');
      flower.push(text);
      flower.push('</div>');
      flower = $(flower.join(''));
      flower.appendTo(wrapper);
      //var r = (index + 1) * secondLineLength;
      if (autoAnimate) {
        animation(flower, r, radian, range, center, text, last);
      }
    }
    // 查看當(dāng)前時間
    function logNowTime() {
      var date = new Date(),
        hour = date.getHours(),
        minute = date.getMinutes(),
        second = date.getSeconds();
      hour = hour < 10 ? "0" + hour : hour;
      minute = minute < 10 ? "0" + minute : minute;
      second = second < 10 ? "0" + second : second;
      $("#time").html("當(dāng)前時間-" + hour + ":" + minute + ":" + second);
    }
    $(document).ready(function () {
      wrapper = $("#wrapper"),
        width = wrapper.width(),
        height = wrapper.height(),
        offLeft = parseInt(wrapper.offset().left),
        range = {
          x: offLeft,
          y: 0,
          x1: offLeft + width,
          y1: height
        },
        center = {
          x: Math.round(width / 2) + offLeft,
          y: Math.round(height / 2)
        };
      initHours(secondLineLength * secondsLineLength + 40, '●', center);
      initMinutes(secondLineLength * secondsLineLength + 20, '●', center);
      initSeconds('●', center, range);
    });  
  </script>
  <style type="text/css" >
    body { margin:0; padding:0; }
    #wrapper { margin:0 auto; width:1000px; height:780px; background:black; }
    .second { width:12px; height:12px; position:absolute; text-shadow:1px 1px 1px green; color:Green; } 
    .minute { color:#DDDDDD; position:absolute;}
    .hour { color:#494949; position:absolute;}
    #time { font-size:30px; line-height:30px; text-shadow:2px 2px 2px green; text-align:center; }
  </style>
</head>
<body>
<div id="time"></div>
<div id="wrapper" >
</div>
</body>
</html>

更多關(guān)于jQuery特效相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常見經(jīng)典特效匯總》及《jQuery動畫與特效用法總結(jié)》

希望本文所述對大家jQuery程序設(shè)計有所幫助。


css

主站蜘蛛池模板: 唐砖演员表| 一元二次方程实际问题| 天鹅套索 电视剧| chinese国产xxx实拍| 郑书允的10部作品| 《哥哥的女人》电影| 霹霹乐翻天| 孕妇直播肚子疼揉肚子| 洛城僵尸| 小数除法竖式50道带答案| 亚纱美| 北京卫视今天节目预告| 红旗车驾驶员个人主要事迹材料 | 黄视频在线网站| 卡士酸奶尽量少吃| 抓特务| 黑帆第三季电视剧完整免费观看高清 | 电影四渡赤水在线观看完整版| 金时厚| 辩论赛作文| 大海在呼唤| 玛丽与魔女之花| 代高政最新短剧| 美国派7| 抖音社区| cctv16体育频道直播| 二年级aab词语| 高中历史知识点总结| 菲律宾电影泡沫| 车仁表图片| 二年级上册道法教学计划| 红海行动2虎鲸行动| 泰国xxx| infrustructure| lanarhoades在线av| 影库| 二年级最佳家长评语| 阿斯美治疗咳嗽效果服法用量| 《瑜伽教练》第二季| 郭德纲7000字微博原文| 韩宝仪|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103