【发布时间】:2015-08-28 21:06:50
【问题描述】:
我正在建立一个网站,对于关于页面,我有一些图片,我想将其淡化为 0.5 不透明度,然后让文字淡入顶部。我的问题是,每当我将鼠标放在其中一个图像上时,它以及它上面的文本都会多次淡入淡出。 Here's 我遇到问题的代码部分的链接。仅当您从包含 div 的外部将鼠标移到图像上时才会出现此问题。
我的 jQuery:
$(document).ready(function() {
$('.fade').mouseenter(function() {
$(this).fadeTo(150, 0.5);
$(this).siblings().fadeIn(150);
}).mouseleave(function() {
$(this).fadeTo(150, 1);
$(this).siblings().fadeOut(150);
});
});
我注意到,当我删除 mouseenter 和 mouseleave 中的第二行代码时,它解决了问题。我试过 mouseover、hover、stopPropogation,我已经浏览了所有这些:
mouseenter event called twice even after stopPropagation
Mouseover and mouseleave trigger every time I move the mouse inside the given element
JQuery mouseover function firing multiple times
How to stop toggle event from being fired multiple times on mouseenter/mouseleave?
jquery mouseover event firing twice
Jquery mouseenter() vs mouseover()
并尝试了他们建议的所有方法,但到目前为止对我来说没有任何效果。有什么想法吗?
【问题讨论】:
标签: javascript jquery html css