Tôi muốn trì hoãn sự kiện di chuột trong jquery. Tôi đang đọc từ một tệp khi người dùng di chuột qua liên kết hoặc nhãn. Tôi không muốn sự kiện này xảy ra ngay lập tức trong trường hợp người dùng chỉ di chuyển chuột qua màn hình. Có cách nào để trì hoãn sự kiện này không?Sự kiện di chuột jquery trễ?
Cảm ơn bạn.
Ví dụ mã:
$(function() {
$('#container a').hover(function() {
$('<div id="fileinfo" />').load('ReadTextFileX.aspx',
{filename:'file.txt'},
function() {
$(this).appendTo('#info');
}
);
},
function() { $('#info').remove(); }
});
});
UPDATE:(1/14/09) Sau khi thêm HoverIntent cắm các mã trên đã được đổi thành phần sau đây để thực hiện nó. Rất đơn giản để thực hiện.
$(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)
}
Cảm ơn cho việc cung cấp sử dụng cho hoverIntent – JavaKungFu