npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@beyonk/svelte-scrollspy

v2.1.2

Published

<p align="center"> <img width="186" height="90" src="https://user-images.githubusercontent.com/218949/44782765-377e7c80-ab80-11e8-9dd8-fce0e37c235b.png" alt="Beyonk" /> </p>

Downloads

286

Readme

Svelte Scroll Spy

js-standard-style CircleCI svelte-v2 svelte-v3

Svelte Scroll Spy component

This component uses IntersectionObservers (and a polyfill for non-supporting browsers like Safari) so that performance is quick and doesn't impact the user's experience.

Usage

This library is pure javascript, so can be used with any framework you like.

Demo

npm run dev // http://localhost:12001

To use within a Svelte application:

npm i -D @beyonk/svelte-scrollspy

Usage

<ScrollSpy>
  <ul>
    {#each sections as section (section.id)}
    <li>
      <SectionHeader id="{section.id}">
        {section.title}
      </SectionHeader>
    </li>
    {/each}
  </ul>
  {#each sections as section (section.id)}
  <ScrollableSection id="{section.id}">
    <h2>{section.title}</h2>
    <p>{section.content}</p>
  </ScrollableSection>
  {/each}
</ScrollSpy>

<script>
  import { SectionHeader, ScrollableSection, ScrollSpy } from '@beyonk/svelte-scrollspy'

  const sections = [
    { id: 'abc', title: 'Some Title', content: 'Lorem ipsum dolor...' },
    { id: 'def', title: 'Some Other Title', content: 'Lorem ipsum dolor...' },
    { id: 'ghi', title: 'A Different Title', content: 'Lorem ipsum dolor...' }
  ]
</script>

You need to set id on each ScrollableHeader and its corresponding ScrollableSection. Besides that, everything else is pretty freeform.

Upon scrolling to the appropriate section of the page, the heading of the section which is topmost visible on the page will get the class 'active'.

Therefore, you could indicate the current section in the example above by highlighting it in red as follows:

<style>
	:global(.beyonk-svelte-scrollspy .active) {
		color: red;
	}
</style>