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

wtc-controller-viewports

v2.0.4

Published

A viewport class for controlling elements on scroll.

Downloads

228

Readme

Viewport

The Viewport class is a controller that provides information on the position of the element within the window. It does this through a combination of IntersectionObserver and request animation frame.

This class extends the element controller and requires registration with the Execute controllers system in order to be instanciated as a component (ie with )

Viewport

| Param | Type | Description | | --- | --- | --- | | element | HTMLElement | The element to use | | settings | object | A settings object that allows settings to be passed to the raw class. These settings are:

  • vpprefix The prefix for the classnames
  • vpstoptopthreshold The threshold to stop the execution of at
  • animationCallback The function to run on animation. Takes the same three parameters as the runAnimation method |

Returns void

The Viewport Class constructor

scrollPos

(getter/setter) Scroll position. This updates the scroll position only if it's changed and then calculated the element's top position based on that.

top

(getter/setter) Top position. This updates the element's top position in pixels only if the value has changed and then calculates the 3 positional percentages - top, middle and bottom and then runs the runAnimation method to perform actions based on these numbers.

playing

(getter/setter) Playing. This is set in response to a callback on the intersection observer and sets up the RaF loop to calculate the scroll position and run the animation.

windowHeight

(getter/setter) The window height. Used to calculate the positional percentages.

elementHeight

Element height. Returns The element's height in pixels.

isOnScreen

(getter/setter) Sets whether the element is onscreen. This is set from the intersection observer callback and updates the classes of the element for use.

classes

The array of classes to remove from the element on scroll.

Returns The classes to remove each time the animation loop is run.

classPrefix

(getter/setter) Sets the prefix for the css classes for the element. Setting this will also set the class list.

animationCallback

(getter/setter) Sets the animation callback for custom behaviour. this function will be called each time the runAnimation function is called. Any provide function will be bound to this instance and takes three params:

  • topPercent;
  • middlePercent; and
  • bottomPercent

runAnimation()

| Param | Type | Description | | --- | --- | --- | | topPercent | number | The percentage distance between the top of the element and the bottom of the screen. | | middlePercent | number | The percentage distance between the middle of the element and the bottom of the screen. | | bottomPercent | number | The percentage distance between the bottom of the element and the top of the screen. |

Returns void

This method is called from the run loop and updates the classes based on the percentages provided to it. This is a public method and so can be called programatically, but the use-cases for doing so are limited.