I have a div with a background image. On hover, I want the image to zoom in slightly. I have it working (see fiddle) but I want it to animate smoothly over 0.3 seconds and then go back smoothly instead of jumping.
How do I do this?
https://jsfiddle.net/ufgnroor/2/
HTML
<div class="portfolio-item">
</div>
CSS
.portfolio-item {
height: 300px;
position: relative;
text-align: center;
cursor: pointer;
margin-bottom: 20px;
background-position: center;
background-size: cover;
background-image: url('http://media4.popsugar-assets.com/files/2014/08/08/878/n/1922507/caef16ec354ca23b_thumb_temp_cover_file32304521407524949.xxxlarge/i/Funny-Cat-GIFs.jpg');
}
.portfolio-item:hover {
background-size: 150%;
-webkit-transition: all 0.3s ease-in-out;
}
For your case you have to set the background-size & the transition before the hover:
.portfolio-item {
background-size: 100%;
transition: all 0.3s ease-in-out;
}
.portfolio-item:hover {
background-size: 150%;
}
https://jsfiddle.net/gv5pjqok/1/
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