这完美无缺,但不知何故,我认为有更简单快捷的方法可以做到这一点。我不确定,我正在寻找建议。这是代码:
/* create a hover event and a click event */
// set the status of whether the box is open or closed
var status = 0;
// remove the css hover state (fall back hover)
$("#testApp").off("hover");
// add a jQuery mouseover and mouseout event
$("#testApp").on("mouseover", function() {
$("#testApp div").css({
"background-image":"url(./images/svg/menucorner-bg-lit.svg)"
});
});
$("#testApp").on("mouseout", function() {
$("#testApp div").css({
"background-image":"url(./images/svg/menucorner-bg.svg)"
});
});
// create a click event
$("#testApp").on("click", function() {
if(status == 0) {
// remove the mouseover and mouseout event when the div opens
$("#testApp").off("mouseover");
$("#testApp").off("mouseout");
$("#testApp div").css({
"background-image":"url(./images/svg/menucorner-bg-lit.svg)",
"height":"200px",
"background-color":"#ccc"
});
return status = 1;
}else{
// add the mouseover and mouseout event when the div closes
$("#testApp").on("mouseover", function() {
$("#testApp div").css({
"background-image":"url(./images/svg/menucorner-bg-lit.svg)"
});
});
$("#testApp").on("mouseout", function() {
$("#testApp div").css({
"background-image":"url(./images/svg/menucorner-bg.svg)"
});
});
$("#testApp div").css({
"height":"50px",
"background-color":"transparent"
});
return status = 0;
}
});
所以基本上它会创建一个悬停状态和一个点击切换。有没有更有效的方法来做到这一点?