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

scroll-snooper

v2.0.0

Published

Pure JavaScript API that goes snooping around elements while scrolling

Downloads

6

Readme

Scroll Snooper Netlify Status

release minified license jsdelivr CodePen

🛼 Pure JavaScript API that goes snooping around elements while scrolling

Getting started

NPM package

npm i scroll-snooper

or as a dev dependency

npm i scroll-snooper --save-dev

Import

import "scroll-snooper";

// your script

CDN

👉 CDN Hosted - jsDelivr

👉 Self hosted - Download the latest release

Quick use

Create watcher to listen to events

ScrollSnooper.create({
    trigger: document.querySelect('.block'),
    onEnter: data => {
        console.log(data);
    },
    onLeave: data => {
        console.log(data);
    },
    onScroll: data => {
        console.log(data);
    },
});

Is in viewport

console.log(ScrollSnooper.isInViewport(document.querySelect('.block')));

or only return true if at least 20% of element is appearing in viewport

console.log(ScrollSnooper.isInViewport(document.querySelect('.block'), 0.2));

Visibility

Get the number of pixels and proportion (%) of the element displaying on the viewport.

console.log(ScrollSnooper.visibility(document.querySelect('.block')));

The most visible element

Select multiple elements and pick out the most visible one based on its pixel displaying on the viewport.

console.log(ScrollSnooper.getTheMostVisible(document.querySelectAll('.blocks')));

or use with create()

ScrollSnooper.create({
    trigger: document.querySelectAll('.blocks'),
    isGetTheMostVisible: true,
    onChange: data => {
        console.log(data);
    },
    onFound: data => {
        console.log(data);
    },
});

Documentation

ScrollSnooper.create({}) : void

| Name | Type | Default | Note | |---------|---------------------|--------------|-------------------------------------------------------------------------------------| | trigger | jQuery, HTMLElement | undefined | Element(s). | | start | string | top bottom | Starting position, top bottom means _"when the top of the trigger hits the bottom |

of the viewport"_, "center center" means "when the center of the trigger hits the center of the viewport". "top 90%" or "bottom 100px" are also accepted. | | end | string | bottom top | Ending position. | | onEnter | function | data => {} | A callback for when the trigger is scrolled into view. | | onLeave | function | data => {} | A callback for when the trigger is scrolled out of view. | | onScroll | function | data => {} | A callback that gets called everytime the scroll position changed (scrolling, resizing). |

When isGetTheMostVisible is true

| Name | Type | Default | Note | |---------------------|----------|------------|-------------------------------------------------------------------------------------------------| | isGetTheMostVisible | boolean | false | Activate the watcher for multiple triggers. | | onChange | function | data => {} | A callback that gets called everytime the most visible element changed (including undefined). | | onFound | function | data => {} | A callback that gets called everytime one of the triggers is scrolled into view. |

ScrollSnooper.isInViewport( element: jQuery | HTML element, proportion: number) : Boolean

Returns true if the element is in the viewport. You can optionally specify a minimum proportion, like ScrollSnooper.isInViewport(element, 0.2) would only return true if at least 20% of the element is in the viewport.

console.log(ScrollSnooper.isInViewport(document.querySelect('.block'), 0.2));

ScrollSnooper.visibility( element: jQuery | HTML element ) : {pixel, proportion}

Get the number of pixels and proportion (%) of the element displaying on the viewport.

console.log(ScrollSnooper.visibility(document.querySelect('.block')));

ScrollSnooper.getTheMostVisible( element: jQuery | HTML element, atLeastPixel: number ) : Object

Select multiple elements and pick out the most visible one based on its pixel displaying on the viewport.

console.log(ScrollSnooper.getTheMostVisible(document.querySelectAll('.blocks')));

Deployment

Start dev server

npm run dev

Build production files (UMD and NPM package)

npm run prod

Build sources from ./web to ./build

npm run build

Build files from ./src to ./dist then publish to npm

npm run publish

License

MIT License

Copyright (c) 2022 Minh-Phuc Bui