我是Jquery的新手,一直在關注一些教程,但這讓我陷入困境。我找到了一個教程來製作一個很好的Jquery時鐘,但我試圖將它轉換爲一個插件。我遇到的問題是我已經看到如何調用一個基於單獨的插件的插件,但這讓我難住。你可以看看我的代碼,並告訴我如何去調用插件嗎?由於調用JQuery插件
HTML:
<head>
<script src="jquery.min.js"></script>
<script src="clock.js"></script>
<script>
// Need to call
</script>
<style>
#clock {
position: relative;
width:280px;
height: 285px;
margin: 20px auto 0 auto;
background: url(images/clockface.png);
list-style: none;
}
#sec, #min, #hour {
position: absolute;
width: 7px;
height: 70px;
top: 125px;
left: 140px;
}
#sec {
background: url(images/second.png);
z-index: 3;
}
#min {
background: url(images/min.png);
z-index: 2;
}
#hour {
background: url(images/hour.png);
z-index: 1;
}
</style>
</head>
<body>
<ul id="clock">
<li id="sec"></li>
<li id="hour"></li>
<li id="min"></li>
</ul>
</body>
JS ...
(function($){
$.fn.mclock = function(){
var defaults = {
var seconds = new Date().getSeconds();
var sdegree = seconds * 6;
var hdegree = hours * 30 + (mins/2);
},
options = $.extend(defaults, args);
console.log(options);
this.each(function(){
setInterval(function() {
var seconds = new Date().getSeconds();
var sdegree = seconds * 6;
var srotate = "rotate(" + sdegree + "deg)";
$("#sec").css({ "transform": srotate });
}, 1000);
setInterval(function() {
var hours = new Date().getHours();
var mins = new Date().getMinutes();
var hdegree = hours * 30 + (mins/2);
var hrotate = "rotate(" + hdegree + "deg)";
$("#hour").css({ "transform": hrotate});
}, 1000);
setInterval(function() {
var mins = new Date().getMinutes();
var mdegree = mins * 6;
var mrotate = "rotate(" + mdegree + "deg)";
$("#min").css({ "transform" : mrotate });
}, 1000); })(jQuery);
$( '#時鐘')mclock()。 ...我看不到任何參數的需要。 –
有點不清楚你想要什麼馬克tbh - 你似乎在說'我怎麼稱呼這個功能',但也說'某個單獨的div'。你想要什麼? –
嗨保羅,使用我得到的錯誤 - 未捕獲TypeError:對象[對象對象]在控制檯中沒有方法'mclock'template.html:8 (匿名函數)。 – Mark