This will be so much code in multi element check.
$(window).scroll(function() {
let top_of_element = $("#element").offset().top;
let bottom_of_element = $("#element").offset().top + $("#element").outerHeight();
let bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
let top_of_screen = $(window).scrollTop();
if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
$('#element').addClass('in-view')
}
else{
$('#element').removeClass('in-view')
}
});
I created this function but was not work:
$(window).scroll(viewport("#element"));
function viewport(selector) {
let top_of_element = $(selector).offset().top;
let bottom_of_element = $(selector).offset().top + $(selector).outerHeight();
let bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
let top_of_screen = $(window).scrollTop();
if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
$(selector).addClass('in-view')
}
else{
$(selector).removeClass('in-view')
}
}
if replace parameter with your selector nothing happened.
Please tell me what I have to do…
Thanks.