这是代码。
HTML
<body>
<h1>111</h1>
<h1>222</h1>
<h1>333</h1>
<h1>444</h1>
</body>
JS
$(function(){
blink("h1", 100);
});
(function(){
$.fn.myBlink = function(speed){
return this.each(function(){
//setInterval(function(){
$(this).fadeOut(speed).fadeIn(speed);
//}, speed);
});
}
}(jQuery));
function blink(selector, speed){
setInterval(function(){
$(selector).myBlink(speed);
}, speed);
}
这很完美。但我想将功能闪烁和插件myBlink结合在一起。如果发布评论代码,它就不起作用。我做错了什么? $(函数(){ 眨眼(&#34; h1&#34;,100); });
(函数(){ $ .fn.myBlink = function(speed){ return this.each(function(){ //的setInterval(函数(){ $(本).fadeOut(速度).fadeIn(速度); //},速度); }); } }(jQuery的));
是的,我找到了答案!
function blink(selector, speed){
setInterval(function(){
$(selector).myBlink(speed);
}.bind(this), speed);
}
答案 0 :(得分:0)
尝试将return语句放入setInterval。它应该工作