
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
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 0 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.