Socket
Socket
Sign inDemoInstall

interserver-svelte

Package Overview
Dependencies
2
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    interserver-svelte

IntersectionObserver simplified


Version published
Maintainers
1
Install size
28.7 kB
Created

Readme

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

FAQs

Last updated on 14 May 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc