svelte-intersection-observer

Detect if an element is in the viewport using the Intersection Observer API

MIT License

Downloads
16.4K
Stars
326
Committers
4
svelte-intersection-observer - Latest Release

Published by metonym 10 months ago

Breaking Changes

  • Drop support for bundled ESM/UMD; code is only distributed as Svelte files
  • Remove IntersectionObserverProps or Entry TypeScript interfaces from IntersectionObserver.svelte.d.ts

Use the Svelte ComponentProps utility to extract component props.

import IntersectionObserver from "svelte-intersection-observer";
import type { ComponentProps } from "svelte";

type Props = ComponentProps<IntersectionObserver>;

Fixes

  • element and root prop types should be null | HTMLElement to support TypeScript strict mode
  • Add exports field to package.json
svelte-intersection-observer -

Published by metonym 10 months ago

Fixes

  • add exports field to package.json to resolve Vite development warnings (8b2f824, branch)
svelte-intersection-observer -

Published by metonym over 1 year ago

Fixes

  • fix threshold prop type to be number | number[] (6992399, #70 by @kevinkace)
svelte-intersection-observer - v0.10.0

Published by metonym almost 3 years ago

Features

  • mark observer for garbage collection after disconnecting (b961e16)

Documentation

  • make prop descriptions consistent with docs (5944a6b)

Refactoring

  • omit redundant null from element and root types as HTMLElement is already nullable (41a3609)
svelte-intersection-observer -

Published by metonym almost 3 years ago

This is a patch release to refresh the documentation published to NPM/Yarn.

Documentation

  • add let: directive example
  • update component prop descriptions
  • use Svelte syntax highlighting for on:observe, on:intersect examples
svelte-intersection-observer -

Published by metonym almost 3 years ago

Documentation

  • update the "Once" example to include the "svelte-intersection-observer" import
  • rename example svite to vite

Refactoring

  • inline entry prop typedef
  • remove @event, @slot artifacts used by sveld to generate initial TypeScript definitions
svelte-intersection-observer -

Published by metonym about 3 years ago

  • improve TypeScript definitions for dispatched events
    • on:observe: event.detail.isIntersecting is a boolean
    • on:intersect: event.detail.isIntersecting can only be true
<IntersectionObserver
  on:observe={(e) => {
    console.log(e.detail.isIntersecting); // boolean
  }}
  on:intersect={(e) => {
    console.log(e.detail.isIntersecting); // true
  }}
/>
svelte-intersection-observer -

Published by metonym about 3 years ago

  • use .svelte.d.ts as the extension for the component TypeScript definition
svelte-intersection-observer - v0.7.1

Published by metonym over 3 years ago

This is a patch release to refresh the documentation published to NPM/Yarn.

Documentation

  • add description for basic usage
  • add on:observe example
  • explain difference between on:observe and on:intersect
  • document IntersectionObserverEntry interface
  • re-order prop table so that once and intersecting are more prominent
svelte-intersection-observer - v0.7.0

Published by metonym over 3 years ago

Features

svelte-intersection-observer - v0.6.1

Published by metonym over 3 years ago

Fixes

  • move intersection observer instantiation to onMount to work in hydration use cases (#13, contributed by @nosovk)
svelte-intersection-observer - v0.6.0

Published by metonym over 3 years ago

Features

  • export observer prop (type IntersectionObserver)
  • dispatch "intersect" event if the observed element isIntersecting the viewport
svelte-intersection-observer - v0.5.0

Published by metonym almost 4 years ago

Features

  • Add support for Server-Side Rendering (SSR)
svelte-intersection-observer - v0.4.0

Published by metonym almost 4 years ago

Features

  • Export intersecting prop

Fixes

  • Remove observer from module context to allow multiple component instantiations (#7)
  • Fix prop type for entry

Documentation

  • Bind the intersecting prop in the demo / Svelte REPL, which is more concise than binding to entry

    <script>
      import IntersectionObserver from "svelte-intersection-observer";
    
      let element;
      let intersecting;
    </script>
    
    <header>
      <strong>Scroll down.</strong>
      <div>
        Element in view?
        <strong class:intersecting>{intersecting ? 'Yes' : 'No'}</strong>
      </div>
    </header>
    
    <IntersectionObserver {element} bind:intersecting>
      <div bind:this={element}>
        {#if intersecting}Element is in view{/if}
      </div>
    </IntersectionObserver>
    
svelte-intersection-observer - v0.3.0

Published by metonym almost 4 years ago

Features

  • Export entry (IntersectionObserverEntry) as a reactive prop

This allows for more concise code:

<IntersectionObserver {element} bind:entry>
  <div class="element" bind:this="{element}">
    {#if entry && entry.isIntersecting}
      Element is in view
    {/if}
  </div>
</IntersectionObserver>
svelte-intersection-observer - v0.2.0

Published by metonym almost 4 years ago

  • add TypeScript definitions
Package Rankings
Top 3.19% on Npmjs.org
Badges
Extracted from project README
NPM
Related Projects