Just wondering how I can get this working 100% correctly. I think I'm nearly there.
Basically, I have an image & when I mouseover, I want an overlay (which is a coloured div) to appear over the top.
I have this semi-working in this fiddle.
<img src="http://mirrorchecker.com/images/rod_160.png" width="160"
class="company-image"/>
<div class="company-image-overlay"></div>
/* CSS */
.company-image
{
}
.company-image-overlay
{
width: 160px;
height: 160px;
background-color: #ffb00f;
z-index: 1;
opacity: 0.5;
position: fixed;
top: 0.5em;
display:none;
}
/* JQUERY */
$('.company-image').mouseover(function()
{
$('.company-image-overlay').show();
});
$('.company-image').mouseout(function()
{
$('.company-image-overlay').hide();
});
The issue seems to be when the overlay appears, the mouse is no longer technically over the .company-image
therefore we get a constant cycling of over / out and the flashing background.
Any ideas?
The simplest solution is to add a wrapping element for both elements:
<div class="wrap">
<img src="http://mirrorchecker.com/images/rod_160.png" width="160" class="company-image" />
<div class="company-image-overlay"></div>
</div>
And place the mouseover
/mouseout
methods to that element instead:
$('.wrap').mouseover(function () {
$('.company-image-overlay').show();
}).mouseout(function () {
$('.company-image-overlay').hide();
});
JS Fiddle demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With