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

@ahkui/appear.js

v1.3.0

Published

utility to run functions when dom elements are visible

Downloads

5

Readme

appear appear

Track the visibility of dom elements and fire user defined callbacks as they appear and disappear.

Demos

Be sure to view the documentation on the project page

Usage

Include appear.js in your page, it has no dependencies.

Call appear() passing in an object with the following:

  • init function to run when dom is interactive, but before appear.js has started tracking.
  • elements required function that returns an htmlcollection of elements to track. The dom will be interactive at this point. Can alternatively be an existing htmlcollection instead of a function.
  • appear function to run when an element is in view, passed the element that has come into view. If defined then appear.js will track elements until they come into view.
  • disappear function to run when an element goes out of view, passed the element that has gone out of view. If defined then appear.js will track elements until they go out of view.
  • reappear if true appear.js will keep tracking elements for successive appears and dissappears. Default is false.
  • bounds increase, in pixels, to the threshold size of the element so it can be "viewable" before it is actually in the viewport.
  • debounce appear.js tracks elements on browser scroll and resize, for performance reasons this check is "debounced" to only happen once for multiple events, 50ms after the last event ends. You can override this value here.
  • deltaSpeed in addition to debouncing, appear.js will also check for items during continuous slow scrolling, you can controll how slow the scrolling should be via this value. Default is 50 (pixels).
  • deltaTimeout after a succesful delta speed check, appear.js will not check for viewable items again until this timeout passes. Default is 500 (ms).
  • done function called when appear.js is no longer tracking any items and event listeners have been removed.

Example

appear({
  init: function init(){
    console.log('dom is ready');
  },
  elements: function elements(){
    // work with all elements with the class "track"
    return document.getElementsByClassName('track');
  },
  appear: function appear(el){
    console.log('visible', el);
  },
  disappear: function disappear(el){
    console.log('no longer visible', el);
  },
  bounds: 200,
  reappear: true
});

api

appear() will return an object with the following:

  • trigger() force a check for viewable elements.
  • pause() temporarily stop tracking elements.
  • resume() resume tracking elements.
  • destroy() permanently stop tracking elements.

Download

source or minified


appear.js logo designed by Magicon from the Noun Project :: Creative Commons - Attribution (CC BY 3.0)