JavaScript
x
11
11
1
this.animate =
2
function(name,color){
3
4
this.style.transform = name;
5
6
this.style.backgroundColor= color;
7
8
};
9
10
document.body.animate("translateY('120px')",'red');
11
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.
JavaScript
1
12
12
1
const animate = function(element, animationObj, colorStr) {
2
element.animate(animationObj, {
3
duration: 2000
4
});
5
element.style.backgroundColor = colorStr;
6
};
7
8
let testElm = document.getElementById("test");
9
10
animate(testElm, {
11
transform: 'translateY(120px)'
12
}, 'red');
JavaScript
1
1
1
<div id="test">test<div>