简体   繁体   English

将鼠标悬停在图像上会导致嵌套div闪烁和mouseout

[英]Hover on image causes flickering and mouseout on nested div

I have a series of photos on a page, and when you hover over them, a white tinted effect fades in, and a title and description appear over it. 我在页面上有一系列照片,当您将鼠标悬停在它们上面时,淡淡的白色效果会淡出,并在其上方显示标题和说明。

The problem I have is that if I hover over the text area, then the white tinted effect keeps fading out again. 我的问题是,如果将鼠标悬停在文本区域上,则白色的效果会再次消失。 It's a strange flickering issue. 这是一个奇怪的闪烁问题。

I need it to work so that regardless of where you hover on the image, it always stays tinted, and when however off it goes back to being just the normal image. 我需要它起作用,以便无论您将鼠标悬停在图像上的什么位置,它都始终保持着色,但是当关闭时,它又回到了普通图像。

My code is below. 我的代码如下。

$('div.project-image a img').mouseover(function() {
    $('div.hover').css('filter', 'alpha(opacity=70)');
            $('div.hover', $(this).parent().parent()).fadeIn(500);
});
    $('div.hover').mouseout(function() {
    $('div.hover').css('filter', 'alpha(opacity=70)');
    $('div.hover', $(this).parent().parent()).fadeOut(500);
});
    $('div.hover').bind('click', function(e) {
    window.location = $(this).parent().children('a').attr('href');

}); });

The CSS styles used are: 使用的CSS样式为:

#content div.project-image (styles the image area)
#content div.hover (displays the white tinted image)
#content div.hover h1 (styles the title)
#content div.hover p (styles the description)

use "mouseEnter" and "mouseLeave" events instead. 请改用“ mouseEnter”和“ mouseLeave”事件。 For pure javascript code those events are propietary and only listened correctly in IE. 对于纯JavaScript代码,这些事件是专有的,只能在IE中正确侦听。 But jquery normalizes them and makes them accesible in all browsers. 但是jquery规范化了它们,并使它们在所有浏览器中都可访问。 They fire only once when you enter the parent element and not every time you hover on each child. 当您输入父元素时,它们只会触发一次,而不会在您将鼠标悬停在每个子元素上时触发。

http://api.jquery.com/mouseleave/ http://api.jquery.com/mouseleave/

http://api.jquery.com/mouseenter/ http://api.jquery.com/mouseenter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM