I want to create an animation that is responsive to the users display height. I created a variable that stores the height of the document in javaScript but I dont know how to create a keyframe animation in javaScript that will allow be to use that variable.
For example, if I wanted this keyframe animation to be created in javaScript, how would I do it.
@keyframes fadeIn {
from{
opacity:0%;
}
to{
opacity:100%;
}
}
2
Answers
You can go for any js animation library. I would recommend GSAP (GreenSock Animation Platform) or anime.js.
For example, in GSAP you can accomplish such things:
Also check out anime.js .They provide a variety of advance css animation properties.
You also can resolve this problem from the other perspective.
You can use CSS Variable inside your keyframes like this
And then you can just set the value of the CSS variable dynamically at any point that you want via your JS:
In the example, I am setting this value on document loaded and window resize events. What guarantees me that –document-height always contains actual height