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

@empatheticbot/on-intersection-element

v0.2.1

Published

Custom Element used to hide and show elements based on whether the viewport is intersecting other elements.

Downloads

1

Readme

On Intersection Element

Custom Element used to hide and show elements based the viewports intersection with other elements.

Installation

$ npm install --save @empatheticbot/on-intersection-element

Import

Import as ES module:

import '@empatheticbot/on-intersection-element'

With a script tag:

<script type="module" src="./node_modules/@empatheticbot/on-intersection-element/dist/index.js">

Note that the path is relative to the root of your project, this may not be the case in your application, so check to make sure your path is correct and the module is being served.

Usage

Example usage to create back to top anchor once header scrolls out of view:

<header id="global-header">
  <h1>On Intersection Element Examples</h1>
</header>
<main>...</main>
<on-intersection of="global-header" hide>
  <a href="#">Back to top</a>
</on-intersection>

Example usage to create a to bottom anchor when header is in view:

<header id="global-header">
  <h1>On Intersection Element Examples</h1>
</header>
<main>...</main>
<footer id="footer"></footer>
<on-intersection of="global-header">
  <a href="#footer">To bottom</a>
</on-intersection>

The on-intersection component recieves the class show when the element with id of is in view. This allows custom styles to be used for animating your element. For instance, this could be used to create a sticky footer button that animates in and out from the bottom of the screen:

on-intersection {
  display: flex;
  justify-content: flex-end;
  position: sticky;
  margin-right: 4vw;
  bottom: 4vh;
  transition: 0.5s;
}

on-intersection:not(.show) {
  bottom: 0;
}

Finally, the changes performed to on-intersection when hiding/showing are:

  • Sets style visibility to hidden|visible
  • Sets style opacity to 0|1
  • Adds/removes class of show

Attributes

  • of - the id of the element to be observed for intersection.
  • hide (optional) - if true, the child elements of on-intersection will be hidden while the element with the of id is intersecting with the viewport.

Development

To install dependencies and build the custom element:

npm install
npm run build

The resulting built custom element can be found in the dist directory. From here you can start a simple HTTP server with npm run start and navigate to http://localhost:3000/examples/. Note that if you make changes to source you will need to run npm run build again and refresh the page.

Tests should be written and live next to the source code it tests. The file name should match that of what it tests with an extension of .test.ts. Tests can be ran with npm run test.

Notes