我是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