Looking to apply a class when a certain screen height is reached? Here's my approach:
window.onscroll = function() {scrollPost()};
function scrollPost () {
var x = window.screen.width;
var i = window.scrollY;
var a = i / x;
animator (a);
slide(a);
}
function slide(x){
var a = (x * 100);
var i = Math.round(a);
console.log(i);
var slideIn = document.querySelector(".slide-in-right");
var slideOut = document.querySelector(".slide-out-left");
if (i >= 90){
slideOut.classList.add("animate");
slideIn.classList.add("animate");
slideIn.style.display = ("block");
}
The issue I'm facing is that the toggle time varies on different screens due to different values. Adding multiple if statements based on screen width seems like an option, but could lead to a lot of clutter.
To solve this, I want the animation to trigger only when the container reaches 100% of the screen height. Any suggestions on how to achieve this?