I'm new at JS, and I wonder how I can add a style with JS, like...
document.getElementById("id").style.transform = "translateX(50%)";
...but without overlapping the style I wrote in the css.
Here's my exaple. CSS:
#falling-block {
margin-top: 21px;
}
@keyframes falling {
from {
transform: translateY(0%);
margin-bottom: 0;
}
to {
transform: translateY(1250%);
margin-bottom: 0;
}
}
And here's my JS:
const ranCol = Math.floor(Math.random()*3);
const fallingBlock = document.getElementById('falling-block');
if (ranCol==0) {
fallingBlock.style.transform = 'translateX(-28%)';
} else if (ranCol==1) {
fallingBlock.style.transform = 'translateX(0%)';
} else if (ranCol==2) {
fallingBlock.style.transform = 'translateX(28%)';
}
fallingBlock.style.animation = 'falling 4s linear infinite';
So it changes the transform in the JS, but I still want the already written transform. Can I just add the translateY and keep the translateX? Thank you!