我想在鼠标悬停在图片上时显示按钮。以下代码可行:
jQuery('.show-image').mouseenter(function() {
jQuery('.the-buttons').animate({
opacity: 1
}, 1500);
}).mouseout(function() {
jQuery('.the-buttons').animate({
opacity: 0
}, 1500);
});
然而,当鼠标从图片移动到按钮(覆盖在图片上的按钮)时,会触发mouseout/mouseenter事件,导致按钮淡出然后再淡入(如果按钮与图像具有相同的类,则它们只会保持淡出状态)。我该如何防止这种情况的发生?我还尝试使用jQuery的hover方法,但结果相同。以下是显示不透明度为1的按钮的图像细节(因为我在图片上方): http://i.stack.imgur.com/egeVq.png 感谢您提前给出的任何建议。
.hover()
简单来说是.mouseenter()
和.mouseleave()
的快捷实现。 - Peter Ajtai