Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop animation and start transition on hover

Tags:

I have a link that's running an infinite animation with the background color. I want to stop the animation and transition into a different background color on hover.

.startlink{     background-color:#206a9e;     color:#fff;     border-radius:15px;     font-family: 'Myriad Pro';     -webkit-animation:changeColor 3.4s infinite;     -webkit-transition:all 0.2s ease-in; }  .startlink:hover{     -webkit-animation-play-state: paused;     background-color: #014a2a; }  @-webkit-keyframes changeColor  {     0%   {background:#206a9e;}     50%  {background:#012c4a;}     100%   {background:#206a9e;} } 

Why is this code not working? And is there an alternate way to get this done? (preferably without Javascript).

like image 295
Sidharth Raja Avatar asked Apr 12 '13 03:04

Sidharth Raja


People also ask

How do I stop an animation from hover?

By setting the animation-play-state to paused on hover, the animation will pause, your click targets will stop moving, and your users will be happy.

Does transition only work with hover?

But transitions are not just limited to use with :hover . You can animate CSS properties, thus use CSS transitions without hover. This is done via transitions using some other CSS techniques, a number of which I've outlined below. I've also included a demo for each example.

How do you pause an animation for some time?

The only way to truly pause an animation in CSS is to use the animation-play-state property with a paused value. In JavaScript, the property is “camelCased” as animationPlayState and set like this: element. style.


1 Answers

Try -webkit-animation: 0;. Demo here. 0 is the default value for animation or what you must set to disable any existing CSS3 animations.

like image 52
Rishabh Avatar answered Oct 04 '22 13:10

Rishabh