I have to keep toggling between two images on mouseover/hover and stop the same when hovering stops,
That I did as
Here is my HTML
<div class="fader">
<img src="image1" />
<img src="image2" />
</div>
Here is my JQuery
$('.fader').hover(function() {
toggleImage();
});
function toggleImage() {
if($('.fader').is(":hover")) {
$('.fader').find("img").fadeToggle(1000);
toggleImage();
}
}
Some CSS I have used for styling
.fader {
display: inline-block;
}
.fader img:last-child {
position: absolute;
top: 0;
left: 0;
display: none;
}
Issue I am facing is, I need to stop my infinite loop of toggleImage()
function on mouseout or when hovering stops.
I tried to check :hover with
$('.fader').is(":hover")
But that doesn't works.
I have to stop infinite loop on mouseout/hovering stops.
Any suggestions?
for more help created one fiddle