我是 Jquery 的新手,并且一直在学习一些教程,但这让我陷入了困境。我找到了一个教程来制作一个很好的 Jquery 时钟,但我正在尝试将它转换为插件。我遇到的问题是我已经看到如何基于单个 div 调用插件,但这让我很难过。你能帮我看看代码并告诉我如何调用插件吗?谢谢
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);