изменить: Заменить ниже (обратите внимание на квадратные скобки)
div.animate([
keyframes,
timing
]);
на:
document.getElementById("content").animate(
keyframes,
timing
);
Здесь рабочий фрагмент кода: (обновлено с шагами в JS)
<style>
body {
background: #808080;
}
.base {
width: 180px;
height: 90px;
background: black;
}
.sample {
animation: play 2s steps(8) infinite;
}
@keyframes play {
0% {
background-color: green;
opacity: 0;
}
100% {
background-color: blue;
opacity: 1;
}
}
</style>
<div class='base sample'></div> <br>
<div id="content" class="base"></div>
<script>
let content = document.getElementById("content");
html = `<div class="base"></div>`;
let doc = new DOMParser().parseFromString(html, 'text/html');
let div = doc.body.firstChild;
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
// keyframes
var keyframes = [{
backgroundColor: 'green',
opacity: 0
}, {
backgroundColor: 'blue',
opacity: 1
}];
// timing
var timing = {
duration: 2000,
easing: 'steps(8)',
iterations: Infinity
}
document.getElementById("content").animate(
keyframes,
timing
);
</script>