I am building an animation via Element.animate(), so I need to create the keyframes like the code below.
However, at some part, I need to set the default value of a css property (like the transformOrigin in the following example). I know the default value is 50% 50%, but I don't want to have a list of all css default values, so I am wondering if there is a method to get those values via JS.
PS: I can get computed styles from an element, but I need to get a default value of it, even after changing the value.
let box = document.querySelector('.box')
let keyframe1 = {
position: 'absolute',
transformOrigin: '0% 0%',
background: 'red',
width: '100px',
height: '100px',
transform: 'rotate(0deg)'
}
let keyframe2 = {
position: 'absolute',
transformOrigin: '0% 0%',
background: 'red',
width: '100px',
height: '100px',
transform: 'rotate(90deg)'
}
box.animate([keyframe1, keyframe2], {
duration: 1000,
iterations: Infinity
})
setTimeout(() => {
keyframe2.transformOrigin = '50% 50%'
box.animate([keyframe1, keyframe2], {
duration: 1000,
iterations: Infinity
})
}, 5000)
<div class="box"></div>