I’m trying to add an ease transition to this hover effect which switches out an image. I want it to fade in so the change is not as dramatic. Here is my function…
function onHover()
{
$(".section").attr('src', 'assets/img/hover-image.jpg');
}
function offHover()
{
$(".section").attr('src', 'assets/img/original-image.jpg');
}
Have you seen the fadeIn() and fadeOut()? Both fadeIn and fadeOut take options which of one is the easing to use. You can even use an option for specialEasing.
Well what you have is nothing but setting an attribute on an element with the class .section. So it if you want an element to fade out when hovered over, change the image, then fade back in then you would use something like…
Just a quick example (and one of many ways to do it) is shown at the pen below. But obviously you will need to tweak this, but you should get the idea.
Note: I am using ‘swing’ as the easing function here, but you can use one of many.