Is it possible in js to write in the css?

All the good time, the task in brief.

var numAnim = new countUp("contr", 2940, 1500, 0, 5);

if (condition) {
numAnim.start();
} 

else {
numAnim.stop();
}


HTML -->

<div class="item" style="z-index: 2; display: block;">
 <span id="contr" class="cifra"></span>
</div>


 <div class="item" style="z-index: 1; display: none;">
 <span id="contr" class="cifra"></span>
</div>
 


This is a simple slider where the image change occurs by changing the css settings.

So, you need to write in the script conditions iffeature numAnim.start(); starts, if the parameter div = display: block;
September 19th 19 at 13:26
2 answers
September 19th 19 at 13:28
Solution
Read about the window.getComputedStyle()
var element = document.getElementById('ID'),
var style = window.getComputedStyle(element),
var display = style.getPropertyValue('display'); - bailey.Okuneva commented on September 19th 19 at 13:31
var element = document.getElementById('ID'),
var style = window.getComputedStyle(element),
var display = style.getPropertyValue('display');
var numAnim = new countUp("contr2", 2940, 1500, 0, 5);

if(display == "block") {
numAnim.start();
}

------------
something like this?) - Tito_Barte commented on September 19th 19 at 13:34
Well, below You are given more concise code. I painted so much detail that You understand the essence that where to get. - bailey.Okuneva commented on September 19th 19 at 13:37
September 19th 19 at 13:30
Solution
var numAnim = new countUp("contr2", 2940, 1500, 0, 5);

if(getComputedStyle(document.getElementById('ID')).display == "block") {
numAnim.start();
}
Works, SPS) only the infection is not reset if display == "none" - bailey.Okuneva commented on September 19th 19 at 13:33

Find more questions by tags CSSJavaScript