jquery自動走動的圓形鐘錶效果程式碼例項
本章節分享一段程式碼例項,它實現了圓形鐘錶走動效果,程式碼如下:
[HTML] 純文字檢視 複製程式碼<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script type="text/javascript"> (function($){ $.fn.drawClock = function(options){ var mainId = $(this); //設定預設引數 var defaultOptions = { 'width': '300px', 'height': '300px', 'margin': '200px auto', 'border': '1px solid #888', 'border-radius': '50%', 'box-shadow': '2px 2px 4px #111' }; var options = $.extend(defaultOptions, options); mainId.css({ 'width': options.width, 'height': options.height, 'margin': options.margin, 'border': options.border, 'border-radius': options['border-radius'], 'box-shadow': options['box-shadow'], 'position': 'relative' }).css({ 'background': '-webkit-gradient(radial, ' + mainId.width()/2 + ' ' + mainId.height()/2 + ', 0, ' + mainId.width()/2 + ' ' + mainId.height()/2 + ', ' + mainId.width()/2 + ', from(#ffe), to(#eee))', 'background': '-moz-radial-gradient(circle closest-side, #ffe 0%, #eee 100%)' }); //鐘表盤中心圓 $("<div id='circle'></div>").appendTo(mainId).css({ 'width': '20px', 'height': '20px', 'border-radius': '50%', 'box-shadow': '0 0 5px rgba(0,0,0,0.8)', 'position': 'absolute', 'z-index': 999, 'background': '-webkit-gradient(radial, ' + mainId.width()/2 + ' ' + mainId.height()/2 + ', 0, ' + mainId.width()/2 + ' ' + mainId.height()/2 + ', ' + mainId.width()/2 + ', from(#ffe), to(#eee))', 'background': '-moz-radial-gradient(circle, #eee 30%, #ffe 100%)' }).css({ 'left': mainId.width()/2 - $('#circle').width()/2, 'top': mainId.height()/2 - $('#circle').height()/2 }); var dateTime = new Date(); var oHours = dateTime.getHours(); var oMinutes = dateTime.getMinutes(); var oSeconds = dateTime.getSeconds(); //初始化時分秒 var hPointer = drawPointer(mainId.width()/2, mainId.height()/2, mainId.width()/2*(3/6), 5, "#333", -90+oHours*30+oMinutes*6/12); var mPointer = drawPointer(mainId.width()/2, mainId.height()/2, mainId.width()/2*(4/6), 4, "#666", -90+oMinutes*6); var sPointer = drawPointer(mainId.width()/2, mainId.height()/2, mainId.width()/2*(5/6), 3, "#f00", -90+oSeconds*6); //運動時分秒 var timer = setInterval(function(){ dateTime = new Date(); oHours = dateTime.getHours(); oMinutes = dateTime.getMinutes(); oSeconds = dateTime.getSeconds(); hPointer.css({'transform': 'rotate(' + (-90+oHours*30+oMinutes*6/12) + 'deg)'}); mPointer.css({'transform': 'rotate(' + (-90+oMinutes*6) + 'deg)'}); sPointer.css({'transform': 'rotate(' + (-90+oSeconds*6) + 'deg)'}); }, 1000); //繪製鐘錶刻度 for(var i=0; i<60; i++){ var width = 3, height = 6, oBcolor = '#111'; if(i%5 == 0){ width = 5; height = 10; } if(i%15 == 0){ oBcolor = 'red'; } $("<div class='clockMark'></div>").appendTo(mainId).css({ 'width': width, 'height': height, 'position': 'absolute', 'top': 0, 'left': mainId.width()/2, 'background': oBcolor, 'transform': 'rotate(' + i*6 + 'deg)', "transform-origin": "0 " + mainId.width()/2+'px' }); } //繪製鐘錶指標 function drawPointer (startx, starty, width, height, bcolor, angle) { var oPointer = $("<div></div>"); oPointer.appendTo(mainId).css({ 'width': width, 'height': height, 'position': 'absolute', 'top': starty, 'left': startx, 'background': bcolor, 'transform': 'rotate(' + angle + 'deg)', 'transform-origin': '0 0' }); return oPointer; } return this; } })(jQuery); $(function(){ $('#clock').drawClock(); }); </script> </head> <body> <div id="clock"></div> </body> </html>
相關文章
- canvas實現的圓形走動鐘錶效果Canvas
- javascript圓形電子鐘錶效果程式碼例項JavaScript
- canvas實現的圓形鐘錶效果程式碼例項Canvas
- javascript圓形鐘錶程式碼例項JavaScript
- canvas繪製圓形鐘錶程式碼例項Canvas
- canvas繪製圓盤走動鐘錶效果Canvas
- css3和js實現的圓形鐘錶效果程式碼例項CSSS3JS
- JavaScript動態圓形鐘錶效果詳解JavaScript
- css3動態圓形鐘錶效果CSSS3
- jquery和css實現的圓形鐘錶效果jQueryCSS
- SVG圓形鐘錶效果SVG
- JavaScript圓形鐘錶效果JavaScript
- js鐘錶效果程式碼例項JS
- JavaScript 動態圓形鐘錶JavaScript
- canvas原型鐘錶效果程式碼例項Canvas原型
- jQuery標題自動頂貼效果程式碼例項jQuery
- canvas繪製鐘錶效果程式碼例項Canvas
- js圓形環繞運動程式碼例項JS
- css實現圓形、橢圓和半圓效果程式碼例項CSS
- jquery實現的滑動軸效果程式碼例項jQuery
- canvas實現的動態心形效果程式碼例項Canvas
- jQuery列表上下垂直滾動效果程式碼例項jQuery
- CSS3圓形時鐘效果程式碼CSSS3
- js秒錶效果程式碼例項JS
- CSS橢圓效果程式碼例項CSS
- jQuery實現的自動播放簡單程式碼例項jQuery
- js和css3實現的圓形鐘錶效果JSCSSS3
- jQuery 動畫效果程式碼例項jQuery動畫
- js能夠自動變動的時間日期效果程式碼例項JS
- canvas擺動效果程式碼例項Canvas
- css繪製圓形程式碼例項CSS
- css 心形效果程式碼例項CSS
- 最為簡單的動態數字時鐘效果程式碼例項
- js元素的震動效果程式碼例項JS
- jquery小球碰撞效果程式碼例項jQuery
- jquery 驗證碼效果程式碼例項jQuery
- canvas圓形時鐘效果Canvas
- 美化滾動條效果程式碼例項