延迟jquery悬停事件?
我想在jquery中延迟一个悬停事件。当用户将鼠标悬停在链接或标签上时,我正在读取文件。如果用户只是在屏幕上移动鼠标,我不希望立即发生此事件。有没有办法推迟事件的发射?
谢谢。
示例代码:
$(function() { $('#container a').hover(function() { $('<div id="fileinfo" />').load('ReadTextFileX.aspx', {filename:'file.txt'}, function() { $(this).appendTo('#info'); } ); }, function() { $('#info').remove(); } });});
更新: (1/14/09) 添加HoverIntent插件后,上面的代码更改为以下代码来实现它。实现起来非常简单。
$(function() { hiConfig = { sensitivity: 3, // number = sensitivity threshold (must be 1 or higher) interval: 200, // number = milliseconds for onMouseOver polling interval timeout: 200, // number = milliseconds delay before onMouseOut over: function() { $('<div id="fileinfo" />').load('ReadTextFileX.aspx', {filename:'file.txt'}, function() { $(this).appendTo('#info'); } ); }, // function = onMouseOver callback (REQUIRED) out: function() { $('#info').remove(); } // function = onMouseOut callback (REQUIRED) } $('#container a').hoverIntent(hiConfig)}
慕虎7371278
墨色风雨