event scroll

$ (window) .scroll (function () { $ ('#elementId'). each (function () { var elPosition = $ (this) .offset (). top; // Position of the element var elHeight = $ (this) .height (); // Height of the element var windowTop = $ (window) .scrollTop (); // Top of the window var windowHeight = $ (window) .height (); // Height of the window if (elPosition < windowTop + windowHeight - elHeight) { $ (This) .addClass ("animation fade-in"); } // adds the class wheh the element is fully in the visible area of the window if (elPosition > windowTop + windowHeight) { $ (This) .removeClass ("animation fade-in"); } // removes the class when the element is not visible in the window if (elPosition + elHeight < windowTop) { $ (This) .removeClass ("animation fade-in"); } // removes the class when the element is not visible in the window }); });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.