I am currently using pure JavaScript for animations without relying on jQuery or any other framework. I'm wondering what the most optimized approach is: Should I create classes for transitions in CSS like below?
CSS class:
.all-div-has-this-class { transition: all 1s; }
.class1 { left: 0; }
.class2 { left: 30px; }
Javscript:
testdiv.className += " class1";
testdiv.className += " class2";
or should I simply initialize the testdiv
position in the CSS and then just update it with testdiv.style.left = "30px";
in the JavaScript code?
It's worth mentioning that these operations are inside setTimeout functions to ensure proper timing. Furthermore, I need the solution to be purely JavaScript without the use of jQuery or any other animation framework.