我使用JQuery mouseenter事件來顯示另一個div內的div。當鼠標進入DIV A時,它會顯示一個較小的DIV B.問題是,當我將鼠標放在DIV B上時,JQuery再次運行mouseenter事件。我想顯示DIV B(內部一個),當鼠標移過它時,不要再次觸發mouseenter事件。雖然在技術上,我的鼠標仍然懸停DIV A.所以換句話說,在DIV B上的Mouseout導致JQuery再次在DIV A上運行mouseenter,這是我所理解的。JQuery mouseenter在重疊div上多次觸發
代碼:
$(document).on("mouseenter", ".si", function (e) {
settingsIcon(e,1);
});
$()
$(document).on("mouseout", ".si", function (e) {
settingsIcon(e,0);
});
function settingsIcon(e, action) {
if (action === 1) // show
{
$(".settings_icon").remove();
var id = parseInt(e.target.id.replace("dvci_", ""), 10);
$("#dvc_" + id).prepend("<div class='settings_icon' ><img class='settings_icon_image' src='settings.png' style='width:59px; height:57px' /></div>");
var icon = $("#dvc_" + id + " .settings_icon");
icon.css({
"left": ($("#dvci_" + id).width()/2) - 30,
"top": parseInt($("#dvci_" + id).css("margin-top").replace("px", ""), 10) + ($("#dvci_" + id).height()/2) - 30
});
$(".settings_icon img").show("scale", {}, 400);
}
else {
// hide
$(".settings_icon").remove();
}
}
的jsfiddle:http://jsfiddle.net/tLUrd/
發佈您的jQuery代碼。並看看event.stopPropagation(); – ryadavilli 2013-02-19 12:51:36
我按照您的要求添加了代碼 – 2013-02-19 13:01:51