jquery 插件里怎么写回调函数
推荐于2018-04-04 · 知道合伙人数码行家
关注
展开全部
$.fn.hoverDelay = function(options){
var defaults = {
self:$(this).css("padding"),
hoverDuring: 200,
outDuring: 200,
hoverEvent: function(){
},
outEvent: function(){
}
};
var sets = $.extend(defaults,options || {});
var hoverTimer, outTimer;
return $(this).each(function(){
var el = this;
$(this).hover(function(){
clearTimeout(outTimer);
hoverTimer = setTimeout(function(){
sets.hoverEvent.apply(el);
}, sets.hoverDuring);
},function(){
clearTimeout(hoverTimer);
outTimer = setTimeout(function(){
sets.outEvent.apply(el);
}, sets.outDuring);
});
});
}
$("a").hoverDelay({
hoverEvent: function(){
//这里怎么调用事件的参数, 当前触发对象又怎么调用呢?
$(this) //this就是每个a了
}
});
var defaults = {
self:$(this).css("padding"),
hoverDuring: 200,
outDuring: 200,
hoverEvent: function(){
},
outEvent: function(){
}
};
var sets = $.extend(defaults,options || {});
var hoverTimer, outTimer;
return $(this).each(function(){
var el = this;
$(this).hover(function(){
clearTimeout(outTimer);
hoverTimer = setTimeout(function(){
sets.hoverEvent.apply(el);
}, sets.hoverDuring);
},function(){
clearTimeout(hoverTimer);
outTimer = setTimeout(function(){
sets.outEvent.apply(el);
}, sets.outDuring);
});
});
}
$("a").hoverDelay({
hoverEvent: function(){
//这里怎么调用事件的参数, 当前触发对象又怎么调用呢?
$(this) //this就是每个a了
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询