示例jsfiddle是here。尝试将红色方块悬停,然后将蓝色方块悬停。为什么会闪烁?如何防止蓝色方块消失?
(这实际上是一个标签,它是前图标,仅在悬停时出现)
JavaScript的:
$("#foo").live("mouseover mouseout", function(e) {
if (e.type == "mouseover") {
$("#foo").append("<div id='bar'>");
} else {
$("#bar").remove();
}
});
CSS:
#foo {
width: 100px;
height: 50px;
background: red;
}
#bar {
width: 10px;
height: 10px;
background: blue;
}
由于
答案 0 :(得分:5)
不确定你的意图是什么,但它是你想要的:http://jsfiddle.net/PXExS/4/
$("#foo").live("mouseenter mouseleave", function(e) {
if (e.type == "mouseenter") {
$("#foo").append("<div id='bar'>");
} else {
$("#bar").remove();
}
});
答案 1 :(得分:4)
你可以通过
实现同样的目标$("#foo").live("hover", function(e) {
$("#bar").toggle();
});
上的工作示例