本文實例為大家分享了js時鐘特效 的具體代碼,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)成立與2013年,先為齊河等服務(wù)建站,齊河等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為齊河企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。js代碼
var canvas = document.getElementById("clock"); var clock = canvas.getContext("2d"); function zhong() { clock.save(); //開始畫外層圓 clock.translate(200, 200); clock.strokeStyle = 'black'; clock.lineWidth = 3; clock.beginPath(); clock.arc(0, 0, 195, 0, 2 * Math.PI); clock.stroke(); //時鐘上的數(shù)字 var shuzi = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2]; clock.font = "30px Arial"; clock.textAlign = "center"; clock.textBaseline = "middle"; shuzi.forEach(function(number, i) { var rad = 2 * Math.PI / 12 * i; var x = Math.cos(rad) * 180; var y = Math.sin(rad) * 180; clock.fillText(number, x, y); }); // 小圓點 for(j = 0; j < 60; j++) { var h = 2 * Math.PI / 60 * j; var m = Math.cos(h) * 180; var n = Math.sin(h) * 180; clock.fillStyle = 'black'; clock.beginPath(); if(j % 5 === 0) { continue; } clock.arc(m, n, 3, 0, 2 * Math.PI); clock.fill(); } } function drawHour(hour,min) { clock.save(); var rad = 2 * Math.PI / 12 * hour; var red = 2 *Math.PI/12/60*min; clock.rotate(rad+red); clock.lineWidth = 10; clock.lineCap = "round"; clock.beginPath(); clock.moveTo(0, 5); clock.lineTo(0, -100); clock.stroke(); clock.restore(); } function drawmin(min) { clock.save(); var rad = 2 * Math.PI / 60 * min; clock.rotate(rad); clock.lineWidth = 5; clock.lineCap = "round"; clock.beginPath(); clock.moveTo(0, 10); clock.lineTo(0, -150); clock.stroke(); clock.restore(); } function drawsec(sec) { clock.save(); var rad = 2 * Math.PI / 60 * sec; clock.rotate(rad); clock.lineWidth = 2; clock.lineCap = "round"; clock.strokeStyle = "red"; clock.beginPath(); clock.moveTo(0, 10); clock.lineTo(0, -180); clock.stroke(); clock.restore(); } function dian() { clock.fillStyle = "white"; clock.beginPath(); clock.arc(0, 0, 2, 0, 2 * Math.PI); clock.fill(); } function xuanzhuan() { clock.clearRect(0,0,400,400); zhong(); var now = new Date(); var hour = now.getHours(); var min = now.getMinutes(); var sec = now.getSeconds(); drawHour(hour,min); drawmin(min); drawsec(sec); dian(); clock.restore(); } xuanzhuan(); setInterval(xuanzhuan, 1000);
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。