Im working on a project where a grid of images are loaded all at once. when the mouse is on hover a certain image, a corresponding gif fades in and then fades out when the mouse moves away from the image.
I was able to get a working fiddle with the code i currently have. i have about 20 images that require this desired effect but my code is long and i feel like there is a better way to write my function where it can fade in and out as well as swapping out the images for gifs. Can someone help/point me in the right direction. still learning here!
code:
HTML
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/FORD-SUPER-BOWL.jpg" alt="" class="img-ford" onmouseover="onHover();" onmouseout="offHover();"/>
</figure>
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/OPERATOR.jpg" alt="" class="img-op" onmouseover="onHover1();" onmouseout="offHover1();"/>
</figure>
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/OPERATOR.jpg" alt="" class="img-op1" onmouseover="onHover2();" onmouseout="offHover2();"/>
</figure>
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/FORD-SUPER-BOWL.jpg" alt="" class="img-ford1" onmouseover="onHover3();" onmouseout="offHover3();"/>
</figure>
JAVASCRIPT
$(document).ready(function () {
onHover();
offHover();
onHover1();
offHover1();
onHover2();
offHover2();
onHover3();
offHover3();
});
function onHover()
{
$(".img-ford").attr('src', 'http://reneinla.com/tasha/style/images/gifs/giphy.gif');
}
function offHover()
{
$(".img-ford").attr('src', 'http://reneinla.com/tasha/style/images/stills/FORD-SUPER-BOWL.jpg');
}
function onHover1()
{
$(".img-op").attr('src', 'http://reneinla.com/tasha/style/images/gifs/giphy.gif');
}
function offHover1()
{
$(".img-op").attr('src', 'http://reneinla.com/tasha/style/images/stills/OPERATOR.jpg');
}
function onHover2()
{
$(".img-op1").attr('src', 'http://reneinla.com/tasha/style/images/gifs/giphy.gif');
}
function offHover2()
{
$(".img-op1").attr('src', 'http://reneinla.com/tasha/style/images/stills/FORD-SUPER-BOWL.jpg');
}
function onHover3()
{
$(".img-ford1").attr('src', 'http://reneinla.com/tasha/style/images/gifs/giphy.gif');
}
function offHover3()
{
$(".img-ford1").attr('src', 'http://reneinla.com/tasha/style/images/stills/OPERATOR.jpg');
}
UPDATE
Thanks for the help! i was able to do some research and found something that works. new fiddle