varmyClock={getSecondDeg:function(){vartime=newDate();varnow_seconds=time.getSeconds();var_deg=now_seconds*6return_deg;},getMinuteDeg:function(){vartime=newDate();varnow_minutes=time.getMinutes();varnow_seconds=time.getSeconds();var_deg=now_minutes*6+now_seconds/10return_deg;},getHourDeg:function(){vartime=newDate();varnow_hours=time.getHours();varnow_minutes=time.getMinutes();var_deg=now_hours%12*30+now_minutes/2;return_deg;},init:function(element){varclock_c=element;//时针varhour_p=document.createElement("div");hour_p.id="hour";//分针varminutes_p=document.createElement("div");minutes_p.id="minutes";//秒针varsecond_p=document.createElement("div");second_p.id="second";//刻度clock_c.appendChild(hour_p);clock_c.appendChild(minutes_p);clock_c.appendChild(second_p);myClock.refush(hour_p,minutes_p,second_p);setInterval(function(){myClock.refush(hour_p,minutes_p,second_p);},1000);},refush:function(hh,mm,ss){hh.style.transform='rotateZ('+myClock.getHourDeg()+'deg)';mm.style.transform='rotateZ('+myClock.getMinuteDeg()+'deg)';ss.style.transform='rotateZ('+(myClock.getSecondDeg()+1)+'deg)';setTimeout(function(){ss.style.transform='rotateZ('+myClock.getSecondDeg()+'deg)';},50);}}varclock=document.getElementById("clock")myClock.init(clock);我想将myClock.init(clock)改成clock.myClock.init()这样的方式调用。还有只允许myClock中的Init()方法能被外部调用,其他方法为私有方法,改如何写。//我刚开始这样写的会报错varclock=function(){init=function(element){}//....returninit;}
添加回答
举报
0/150
提交
取消