(function(factory) { if (typeof define === "function" && define.amd) { // AMD模式 define(["jquery"], factory); } else { // 全局模式 factory(jQuery); } }(function($) { $.fn.initClock = function(opt){ var me = $(this); var placename = opt['placename']?opt['placename']:"北京时间"; var xhour=opt['hour']?opt['hour']:0; var clock = [ ''].join(''); $(clock).fadeIn().appendTo(me); var h="
"+ "
"+placename+"
"+ "
"+ "
"; me.append(h); Clock(); function Clock(){ //get the date and time var date = new Date().getDate(),//get the current date hours = new Date().getHours(),//get the current hour minutes = new Date().getMinutes(), //get the current minute seconds = new Date().getSeconds();//get the current second if((hours+xhour)>24){ date++; }else if((hours+xhour)<0){ date--; hours=36+hours+xhour; } hours=hours+xhour; me.find(".s-date").html(date); //show the current date on the clock var hrotate = hours * 30 + (minutes / 2); //i.e 12 hours * 30 = 360 degrees me.find(".s-hours").css({ 'transform' : 'rotate('+ hrotate +'deg)', '-moz-transform' :'rotate('+ hrotate +'deg)', '-webkit-transform' :'rotate('+ hrotate +'deg)' }); var mrotate = minutes * 6; //degrees to rotate the minute hand me.find(".s-minutes").css({ 'transform' : 'rotate('+ mrotate +'deg)', '-moz-transform' :'rotate('+ mrotate +'deg)', '-webkit-transform' :'rotate('+ mrotate +'deg)' }); var srotate = seconds * 6;//for the rotation to reach 360 degrees //i.e 60 seconds * 6 = 360 degrees. me.find(".s-seconds").css({ 'transform' : 'rotate('+ srotate +'deg)', '-moz-transform' :'rotate('+ srotate +'deg)', '-webkit-transform' :'rotate('+ srotate +'deg)' }); var thours=hours; if(hours<10){ thours = "0"+hours; } var tminutes=minutes; if(minutes<10){ tminutes = "0"+hours; } var tseconds=seconds; if(seconds<10){ tseconds = "0"+seconds; } me.find(".time").html(thours+":"+tminutes+":"+tseconds ); setTimeout(Clock,1000); } } }))