父子元素select悬浮代码,兼容火狐

时间:2022-12-20 20:05:29
    //公共切换方法
function SwitchCommon() {
//悬浮显示
$(document.body).on("mouseenter", "[hex-eidtstate]", function (event) {
event.stopPropagation();
//发布对象特殊处理
if ($(this).attr("hex-eidtstate") == "publish") {
$(this).find(".name").addClass("hide");
$(this).find(".panel").removeClass("hide");
return false;
}
$(this).find(".name").each(function () {
if ($(this).hasClass("hide")) {
$(this).removeClass("hide");
} else {
$(this).addClass("hide");
}
})
})
$(document.body).on("mouseleave", "[hex-eidtstate]", function (event) {
event.stopPropagation();
//发布对象特殊处理
if ($(this).attr("hex-eidtstate") == "publish") {
$(this).find(".panel").addClass("hide");
$(this).find(".name").removeClass("hide");
return false;
}
$(this).find(".name").each(function () {
if ($(this).hasClass("hide")) {
$(this).removeClass("hide");
} else {
$(this).addClass("hide");
}
})
})
}
    //火狐浏览器增强代码
function firefoxUpdate() {
var agentInfo = navigator.userAgent.toLowerCase();
//如果是'火狐'
if (agentInfo.indexOf('firefox') > 0) {
console.log("firefox");
//对于火狐浏览器,select作为子元素,展示option内容时,会触发父元素的mouseleave,造成无法选中发情况
$(document.body).on("mouseover", "select", function (event) {
event.stopPropagation();
})
$(document.body).on("mouseout", "select", function (event) {
event.stopPropagation();
})
$(document.body).on("change", "select", function (event) {
$(this).parents("[hex-eidtstate]").trigger("mouseleave");
})
}
}