Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

intersection-observer-amd

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intersection-observer-amd

A polyfill for IntersectionObserver, served as AMD

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by80%
Maintainers
1
Weekly downloads
 
Created
Source

IntersectionObserverAMD

The original, official W3C IntersectionObserver Polyfill, served in AMD.

Why AMD?

Because with AMD you can load the IntersectionObserver only where it's needed, as dependency of another script, e.g. vanilla lazyload.

How to use

Insert Require.JS's script (or another AMD module loader) in your page.

<script src="https://cdn.jsdelivr.net/npm/requirejs@2.3.6/bin/r.min.js"></script>

In your script, create a dependencies array. For example, if you need IntersectionObserver polyfill and vanilla-lazyload, do like that:

var dependencies = [
    "IntersectionObserver" in window
        ? null
        : "https://cdn.jsdelivr.net/npm/intersection-observer-amd@2.0.0/intersection-observer.amd.min.js",
    "https://cdn.jsdelivr.net/npm/vanilla-lazyload@11.0.5/dist/lazyload.amd.min.js"
];

Finally, use require to execute your script, having the dependecies loaded in the right order and ready to use.

// _ is always null, since the polyfill is attached to the window object
require(dependencies, function(_, LazyLoad) {
    window.ll = new LazyLoad({
        elements_selector: ".lazy",
        // More options?
    });
});

DEMO - SOURCE


To update this in case the guys at W3C improve their polyfill:

rollup --format=amd --output=intersection-observer.amd.js -- intersection-observer.js

Keywords

FAQs

Package last updated on 13 Mar 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc