I'm currently working on adding a dark transparent overlay to the product div whenever someone hovers over the product image. I've successfully created overlays for the entire screen in the past using similar logic, but this time it's behaving strangely. Despite trying to use mouseenter and mouseleave events, the overlay keeps appearing and disappearing even when my mouse pointer is still on the image. It seems like the overlay is targeting the entire screen instead of just the box1 element in jQuery.
HTML
<div id="box1">
<img src="http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png" alt="orange" title="orange" />
<a href="#">View Details</a>
</div>
CSS
div#box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
}
div#box1 > img {
position: absolute;
z-index: 2000;
max-height: 240px;
}
div#box1 >a {
display: none;
position: absolute;
top:100px;
left: 40px;
margin: 10px 0 0 10px;
z-index:3000;
background: white;
text-decoration: none;
}
div#box1:hover a {
display:block;
}
#mask {
display:none;
background: #000;
position:fixed;
left: 0;
top: 0;
z-index: 2500;
width: 100%;
height: 100%;
opacity: 0.75;
}
JQuery
$('#box1 img').mouseenter(function () {
$('#box1').append('<div id="mask"></div>');
$('#mask').fadeIn(400);
});
$('#box1 img').mouseleave(function () {
$('#mask').fadeOut(400, function () {
$('#mask').remove();
});
});
If you have any insights on what might be causing this issue or how I can fix it, your assistance would be greatly appreciated. Thank you!