I have three images in a row. I want to enlarge the one that the mouse is over until the mouse is moved off of it. This sort of works in my jsfiddle but, as you can see, the animation doesn't stop after enlarging. The other threads on this problem say to set the iteration count and forwards options, which I've done. The only other solution I could find was to use javascript to control it. Is there a way to do this with just css? Here's my code:
<style>
#set2 {margin-left:40px; display:inline-block}
#set2:hover {
-webkit-animation: enlarge 5s;
animation: enlarge 5s;
animation-fill-mode: forwards;
animation-iteration-count: 1;
}
@-webkit-keyframes enlarge {
25% {
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
}
</style>
<div class="banner_set">
<ul class="nav">
<li id="set2" class="nav-items"><a href="example.com"><img src="example1.jpg"></a></li>
<li id="set2" class="nav-items"><a href="example.com"><img src="example2.jpg"></a></li>
<li id="set2" class="nav-items"><a href="example.com"><img src="example3.jpg"></a></li>
</ul>
</div>
Your keyframe set at
25%
means your element will be scaled 1/4 of the way through the animation, then not scaled at the end. If you just want a smooth scale up and that's all, use100%
(and I would suggest, reduce the duration!).I updated your fiddle. The weird image styling is so we can see your images.
Is there a specific reason you're using the animation approach rather than a transition?
Since the desired behavior is to toggle between two animated states, perhaps the transition is an easier way to approach it.
Using your example code: