Is there a way to change the duration of a CSS3 keyframes animation with JavaScript? In CSS you can do that with the animation-duration property:
animation-duration: 1s;
The JavaScript should be raw, i don't want to include jQuery or other JS librarys into my site.
You can assign css classes in javascript and put your transition/duration/animation in those css classes Or you can assign your css directly in javascript.
document.getElementById('your_id').style.animationDuration="1s";
for cross browsers we can use o,moz,ms and webkit as prefix.
Example-:
document.getElementById('your_id').style.webkitTransitionDuration="1s";
EXAMPLE
function blink()
{
document.getElementById('blink').className = "animated blink_css";
}
// In css
.animated {
-webkit-animation-fill-mode:both;
-moz-animation-fill-mode:both;
-ms-animation-fill-mode:both;
-o-animation-fill-mode:both;
animation-fill-mode:both;
-webkit-animation-duration:1s;
-moz-animation-duration:1s;
-ms-animation-duration:1s;
-o-animation-duration:1s;
animation-duration:1s;
}
@keyframes 'blink' {
0% { background: rgba(255,0,0,0.5); }
50% { background: rgba(255,0,0,0); }
100% { background: rgba(255,0,0,0.5);
}
//try moz for mozilla,o for opera and webkit for safari and chrome
.blink_css {
-webkit-animation-name: blink;
-moz-animation-name: blink;
-o-animation-name: blink;
animation-name: blink;
}
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