
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
lazy-observer
Advanced tools
Observer module with Intersection Observer to execute a function when the element is intersecting
lazyObserver
is a minimalist script to easily execute function when HTML element is intersecting. Callback can be exececuted once or every trigger.
More information about the IntersectionObserver
API on MDN.
The plugin is available as the lazy-observer
package name on npm and Github.
npm i --save-dev lazy-observer
yarn add --dev lazy-observer
lazyObserver
was built for Node.js >=8.11.2
.
The following example display a console.log
statement when the .footer
HTML element is positioned at one screen height.
const LazyObserver = require('lazy-observer');
const lazyObserver = new LazyObserver({
element: document.querySelector('.footer'),
onIntersection: () => {
console.log('Function is triggered');
}
});
lazyObserver.observe();
The following example displays a console.log
statement each time the HTML .footer
element is positioned at one screen height.
const LazyObserver = require('lazy-observer');
const lazyObserver = new LazyObserver({
element: document.querySelector('.footer'),
once: false,
onIntersection: () => {
console.log('Function is triggered');
}
});
lazyObserver.observe();
The following example displays a console.log
statement when the HTML .footer
element is positioned directly at the bottom of the screen.
const LazyObserver = require('lazy-observer');
const lazyObserver = new LazyObserver({
element: document.querySelector('.footer'),
rootMargin: '0px 0px 0px 0px'
onIntersection: () => {
console.log('Function is triggered');
}
});
lazyObserver.observe();
The following example displays a console.log
statement when the HTML .footer
element is positioned directly at the bottom of the screen.
const LazyObserver = require('lazy-observer');
const lazyObserver = new LazyObserver({
element: document.querySelector('.footer'),
rootMargin: '0px 0px 0px 0px'
onIntersection: () => {
import(/* webpackChunkName: "footer-video" */ 'footer-video.js'
).then(() => {
console.log('Module footer-video is loaded');
});
}
});
lazyObserver.observe();
element
HTMLElement
Tells to the function the target element.
onIntersection
function
Specifies the function to execute when the element is intersecting.
once
boolean = true
Specifies the function is the callback is executed once or at every trigger.
rootMargin
string = 0px 0px ${window.innerHeight}px 0px
Specifies the function the offset for the Intersection Observer.
lazyObserver is licensed under the MIT License.
Created with ♥ by @yoriiis.
1.0.1
package.json
FAQs
Observer module with Intersection Observer to execute a function when the element is intersecting
The npm package lazy-observer receives a total of 3 weekly downloads. As such, lazy-observer popularity was classified as not popular.
We found that lazy-observer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.