When the browser registers your CSS ad, it registers the animation name background1 and duration 10s , and then immediately starts the animation. If you want to restart the animation with a new duration, you must wait for the animation to finish or add a new animation name with a new duration.
You can test this script: http://jsfiddle.net/mfdj/Phnf5/9/
- You can always immediately call the animation when changing the name
- You can restart the same animation by changing only the duration, only if you set a different value for the duration and do it after the current animation is completed
Since your initial animation lasts 10 seconds, and you want to immediately call the duration in a randomized time, you should simply delete this announcement:
#background1 { -webkit-animation: background1 10s; }
and you should get the desired result.
Please note that there are some quirks in how browsers handle rewrite / rewrite css animations with the same name, but with different durations. For example, in the sample script, Chrome handles shaking and flash animations differently. Try to start the animation for 10 seconds, and then interrupt it with a one-second animation with the same name. The shake will end for 10 seconds, and the flash will simply clear the animation. However, if you switch from flash to shake (and vice versa), the animation always starts fresh. These are the quirks of running css animations you should be aware of.
source share