this.animate =
function(name,color){
this.style.transform = name;
this.style.backgroundColor= color;
};
document.body.animate("translateY('120px')",'red');
Advertisement
Answer
As a minimum you need an animation object and a duration for the animation Element.animate(). And then I think you got some of your code upside down.
const animate = function(element, animationObj, colorStr) {
element.animate(animationObj, {
duration: 2000
});
element.style.backgroundColor = colorStr;
};
let testElm = document.getElementById("test");
animate(testElm, {
transform: 'translateY(120px)'
}, 'red');<div id="test">test<div>