document.addEventListener("DOMContentLoaded", function(event) { function checkVisibility() { jQuery(".toAnimate").each(function() { let topOfElement = jQuery(this).offset().top; let bottomOfElement = topOfElement + jQuery(this).outerHeight(); let bottomOfScreen = jQuery(window).scrollTop() + jQuery(window).innerHeight(); let topOfScreen = jQuery(window).scrollTop(); let offset = 50; if (window.matchMedia("only screen and (max-width: 767px)").matches) { offset = 0; } if ((bottomOfScreen > topOfElement + offset) && (topOfScreen < bottomOfElement)) { jQuery(this).addClass('show'); } else { jQuery(this).removeClass('show'); } }); } jQuery(window).on('scroll', checkVisibility); checkVisibility(); // הפעל את הפונקציה גם בעת הטעינה });