I have a svg image element in my site. i want to hide that image on mouseover and show on mouseout.
But, i have a strange problem that the image flickers on mouseover.
I tried hiding the image though css and jquery. In both approaches i encountered the same error.
SVG
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<image x="20" y="20" class="imghideshow" width="300" height="80"
xlink:href="http://cdn1.iconfinder.com/data/icons/musthave/128/Help.png" />
</svg>
CSS
.imghideshow:hover
{
visibility:hidden;
}
http://jsfiddle.net/GMd8w/
Please help me to recover the flicker problem. All i want is to hide the image on hover and show on mouseout.
Edited Scenario based on the answers given below.
Well implementing opacity solved flickering issue. But reproduces another problem when i implemented that css property.
So let me explain my full requirement.
I have two overlapped images.(i.e.,) child image overlapped on parent. when i click on parent image, it should trigger a function in js. since child image is not completely hidden here, i cant click on the child overlapped area of parent. check this fiddle.
http://jsfiddle.net/VwmEU/
Expected output is:
When i hover on child, it should hide and i should be able to trigger parent function.
Thanks.
The problem is just that visibility hidden interferes with the element hover . All you need is to use another way to hide it. for instance
.imghideshow:hover
{
opacity: 0;
}
updated fiddle
new solution
There isn't much more that can be done, I think.
Another idea, that could work depending on the scenario. The upper image has no mouse interaction. It's the lower image that handles the events, and so has to make the other one transparent.
CSS:
#img2 {
pointer-events: none;
}
#img1 {
cursor:pointer;
}
#img1:hover ~ #img2 {
opacity: 0;
}
And, if this one can't do the trick (it depends on the layout, that I don't know ... ) there is a last idea: do the very first option that you had (visibility hidden) but then put a delay in the hover-out of say 3 seconds. The only problem will be a small flickering every 3 seconds.
After your update, I moved to something totally different to make it works :
SVG
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg">
<g class="first">
<!-- Both images here -->
<rect x="25px" y="25px" width="150" height="100" class="green" />
<rect x="50px" y="50px" width="150" height="100"/>
</g>
<g class="hover">
<!-- The hover state -->
<rect x="25px" y="25px" width="150" height="100" class="green" id="click" />
</g>
</svg>
jQuery
$('.first').mouseenter(function() {
$(this).hide();
$('.hover').show();
});
$('.hover').mouseleave(function() {
$(this).hide();
$('.first').show();
});
$('#click').click(function() {
alert('clicked');
});
See the updated fiddle.
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