Trigger a CSS animation when a section of a landing page scrolls into view for the first time.
Lazy-load images or videos only when they are about to become visible, reducing initial page load time.
Track which content sections a user has actually seen by firing an analytics event when an element enters the viewport.
Show or hide a call-to-action button based on the user's scroll position relative to a specific element.
in-view.js is a small JavaScript utility for web pages that tells you when a specific element on the page scrolls into or out of the visible area of the browser window. This is useful for things like triggering animations when a section comes into view, lazy-loading images, or tracking whether a user has seen a piece of content. You give it a CSS selector, then attach functions to the enter and exit events. When an element matching that selector scrolls into view, your enter function runs. When it scrolls back out, your exit function runs. You can also use once instead of on if you only want the function to fire a single time. The library includes a few configurable options. The offset setting lets you adjust when an element is considered visible relative to the edge of the browser window, so you can trigger things a bit before or after the element fully crosses the edge. The threshold setting controls how much of the element needs to be visible before the event fires: zero means any tiny portion counts, while one means the entire element must be on screen. There is also a test option that lets you replace the visibility logic entirely with your own custom function. On the performance side, the library attaches a single throttled listener to the scroll, resize, and load events on the window, checking no more than once every 100 milliseconds. It is about 1.9 kilobytes when compressed. The README also notes that the library is designed to eventually use the browser's built-in IntersectionObserver API where available, which is the more modern way to handle this type of detection. The library works in modern browsers and Internet Explorer 9 and later. It is licensed under MIT.
← camwiegert on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.