zhanggang 2019-09-26
有个延时绑定事件的需求, 如等待鼠标停留在某图片上面一段时间之后才展示浮动层, 以避免鼠标滑过屏幕时一片乱闪. 一时找不到合适的插件, 所以自己写了个.
// 定义
(function($){
$.fn.lazybind = function(event, fn, timeout, abort){
var timer = null;
$(this).bind(event, function(){
timer = setTimeout(fn, timeout);
});
if(abort == undefined){
return;
}
$(this).bind(abort, function(){
if(timer != null){
clearTimeout(timer);
}
});
};
})(jQuery);
// 使用
$('#my_img').lazybind(
'mouseover',
function(){
alert(1);
},
240,
'mouseout');<table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%&qu