Issue
let second = document.querySelector('.second');
let secondNed = 0;
setInterval(function () {
secondNed += 6;
if (secondNed == 360) {
secondNed = 0;
}
second.style.transform = `rotate(${secondNed}deg);`
console.log(secondNed);
}, 1000);
So my question is how can I put variable inside style?
( In this specific case - how can I set CSS transform property using the secondNed variable )
Solution
Remove the semicolon from the value of the CSS property.
second.style.transform = `rotate(${secondNed}deg)`;
// note semicolon is outside the string
Alternatively, you could set the CSS rotate
property instead.
second.style.rotate = secondNed + 'deg';
Answered By - Unmitigated
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.