Q
Q
qo_0p2015-10-26 08:55:56
css
qo_0p, 2015-10-26 08:55:56

How to set CCS animation via javascript?

Good afternoon!
I'm trying to write a script that takes words one by one from an array and increments them using css animation making them transparent until they dissolve. Then a new word.
Apparently, since I'm generating div spans via js code, predefined styles don't work on them. But I don’t know how to set css animation through js code. Can you advise?

var height = window.innerHeight;
var width = window.innerWidth;

var arr = ["hello", "privet", "nihao"];
var i = 0;

document.write("<div  style='height:" + height + "px; width:" + width + "px;'><span id='word'></span></div>");

function change_bg() {
    document.getElementById('word').innerHTML = arr[i];
    document.getElementById('word').style.trasition = 'font-size 10em 2s';

    if (i>1) i = 0; else i++;
    }

setInterval(change_bg, 3000);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
monochromer, 2015-10-26
@monochromer

After setting the animation properties, you need to force a layout reflow.
Ways .
Example .

V
Vladimir @, 2015-10-26
@dar6k6night

document.getElementById('word').style.cssText = " transition: font-size: 10em 2s;";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question