Socket
Book a DemoInstallSign in
Socket

interserver-svelte

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interserver-svelte

IntersectionObserver simplified

0.1.2
latest
Source
npmnpm
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Interserver Svelte

npm package npm bundle size NPM GitHub last commit

IntersectionObserver simplified

Checkout the main interserver package.

Features

  • Tiny (~1kb minified)
  • TypeScript ready

Installation

With yarn:

yarn add interserver-svelte

With npm:

npm install --save interserver-svelte

Usage

The createInterserver function takes the same options as the interserver function (top, right, bottom, left and once).

<script>
  import createInterserver from 'interserver-svelte';

  let container;

  const intersecting = createInterserver(() => container);

  $: if ($intersecting) {
    console.log("Now you see me!");
  } else {
    console.log("Oh, the darkness...");
  }
</script>

<div bind:this={container}>
  ...
</div>

Example

You can build a LazyImage component, that only requests an image, when it is approaching the viewport:

<!-- LazyImage.svelte -->
<script>
  import createInterserver from 'interserver-svelte';

  export let alt = '';
  export let src = '';
  export let srscet = null;

  let container;

  const intersecting = createInterserver(() => container, {
    once: true,
    top: 50,
    right: 50,
    bottom: 50,
    left: 50,
  });

  $: src = $intersecting ? src : null;
  $: srcset = $intersecting ? srcset : null;
</script>

<img {...$$props} {src} {srcset} {alt} bind:this={container} />

License

MIT

Keywords

IntersectionObserver

FAQs

Package last updated on 14 May 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.