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

staydown

v2.0.3

Published

Keep overflowed containers scrolled down, but allow user intervention

Downloads

457

Readme

StayDown

Logs and chats often have the style of appending new lines to the bottom, and keeping scrolling pinned to the bottom, unless a user indicates intention not to keep it pinned to the bottom by scrolling up from the bottom. Images add a complication, as they are added to the dom, but later change the size of the overflow. StayDown looks at all added element trees for images, and checks the scrolling again when the image has finished loading.

StayDown keeps track of user intention for pinning the element scroll to the bottom, as elements are added, and checks at an interval. When a user scrolls up, StayDown stops scrolling down for the user, but re-initializes when the user scrolls back down to the bottom.

Optionally, images can be replaced with a "spinner" loading image to make image loading a better user experience. Otherwise, loading images can resize and not scroll down until they are finished loading.

Install

NPM

Module

You can require this as a CommonJS module.

const StayDown = require('staydown');

Or you can import this as a ES6/ECMAScript 2016 module.

import StayDown from 'staydown';

Example

const staydown = new StayDown({
    target: scrolling_element,
    interval: 1000,
    max: 50,
    spinner: "https://i1.wp.com/cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif",
    stickyHeight: 10,
    callback: function (event, msg) {
      console.log("got event:", event);
      console.log("event msg:", msg);
    }
});
staydown.append(new_element);

Options

| Option | Required | Default | Description | |--------------|:--------:|--------:|----------------------------------------------------------| | target | ✓ | None | Target Element | | interval | ✗ | 1000 | Milliseconds to check if MutationObserver is unsupported | | spinner | ✗ | None | URL to spinner image (gif) | | max | ✗ | 0 | If not 0, remove oldest elements greater than max old | | stickyHeight | ✗ | 10 | Number of pixels to consider bottom from bottom | | callback | ✗ | None | function (eventType, msg) |

Events:

The event callback is called with an event type whenever ScrollDown does something.

  • lock: lock to the bottom (at the beginning and when user scrolls back down)
  • release: release from the bottom (usually due to user scroll up)
  • scrolldown: whenever the view is scrolled down by StayDown
  • append: when an element is appended
  • checkfailed: when the interval check happens, it isn't scrolled down, and it is locked
  • removechild: when max items have been exceeded, and topmost child is removed
  • imageload: when an image loads in the overflow element, scrolling is checked
  • windowresize: when the window is resized, scrolling is checked

Occasional Check

When the browser doesn't have Mutation Observer support, a check interval is used for the case of images or dom mutations happening without using the this StayDown's append function.

Building

git clone [email protected]:fritzy/staydown.git
cd staydown
npm install
npm run build

License

The MIT License (MIT)

Copyright (c) 2014-2019 Nathanael C. Fritz