HTML5時鐘,html5

來源:互聯網
上載者:User

HTML5時鐘,html5

執行個體:http://download.csdn.net/download/l294333475/7941639

<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>劉鵬</title></head><body><div style="width:520px;margin:0 auto;"><canvas id="clock" width="520" height="520">您的瀏覽器不支援canvas標籤</canvas></div><script type="text/javascript">var canvas = document.getElementById('clock');var clock = canvas.getContext('2d');function drowClock(){//清除畫布clock.clearRect(0, 0, 800, 800);var now = new Date();var secd = now.getSeconds();var min = now.getMinutes();var hour = now.getHours();//小時必須擷取浮點類型(小時+分數轉化的小時)//時間格式19:23:30//將24小時進位裝換為12小時進位hour = hour + (min / 60);hour = hour > 12 ? hour - 12 : hour;//背景clock.beginPath();clock.lineWidth = 10;clock.strokeStyle = "blue";clock.arc(250, 250, 200, 0, 360, false);clock.stroke();clock.closePath();//刻度//時刻度for (var i = 0; i < 12; i++) {clock.save();//設定時針的粗細clock.lineWidth = 7;//設定時針的顏色clock.strokeStyle = "#000";//先設定0,0點clock.translate(250, 250);//再設定旋轉角度clock.rotate((i * 30) * Math.PI / 180);//角度*Math.PI/180=弧度clock.beginPath();clock.moveTo(0, -170);clock.lineTo(0, -190);clock.closePath();clock.stroke();clock.restore();}//分刻度for (var i = 0; i < 60; i++) {clock.save();//設定時針的粗細clock.lineWidth = 3;//設定時針的顏色clock.strokeStyle = "#000";//先設定0,0點clock.translate(250, 250);//再設定旋轉角度clock.rotate((i * 6) * Math.PI / 180);//角度*Math.PI/180=弧度clock.beginPath();clock.moveTo(0, -180);clock.lineTo(0, -190);clock.closePath();clock.stroke();clock.restore();}//時針clock.save();clock.lineWidth = 7;clock.strokeStyle = "black";clock.translate(250, 250);clock.rotate(hour * 30 * Math.PI / 180);clock.beginPath();clock.moveTo(0, -140);clock.lineTo(0, 10);clock.stroke();clock.closePath();clock.restore();////分針clock.save();clock.lineWidth = 5;clock.strokeStyle = "black";clock.translate(250, 250);clock.rotate(min * 6 * Math.PI / 180);clock.beginPath();clock.moveTo(0, -160);clock.lineTo(0, 10);clock.stroke();clock.closePath();clock.restore();//秒針clock.save();clock.lineWidth = 3;clock.strokeStyle = "red";clock.translate(250, 250);clock.rotate(secd * 6 * Math.PI / 180);clock.beginPath();clock.moveTo(0, -170);clock.lineTo(0, 10);clock.closePath();clock.stroke();//畫交叉點clock.beginPath();clock.arc(0, 0, 5, 0, 360, false);clock.closePath();clock.fillStyle = "gray";clock.fill();clock.stroke();clock.beginPath();clock.arc(0, -150, 5, 0, 360, false);clock.closePath();clock.fillStyle = "gray";clock.fill();clock.stroke();clock.restore();}//使用setInternal(代碼,(毫秒)時間)  讓時鐘動起來drowClock();setInterval(drowClock, 1000);</script></body></html>



html5的時鐘裡面的代碼顏色改了還是不變呀

對body標籤設樣式
 
html怎製做時鐘

HTML5可以的,你可以去搜尋一下“兄弟連HTML5”,然后里面有視頻教程的,你跟著做就可以做出來了
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.