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-to-top-wc

v1.0.22

Published

scroll page up

Downloads

34

Readme

<scroll-to-top-wc>

This Web Component scrolls the page to the top upon clicking the toast notification. The notification will display once a certain scroll depth is reached and remain visible from this point onwards. For very long pages this is a quick shorcut to the top of the page rather than having to use the scroll bar which can be cumbersome.

Install with

npm i scroll-to-top-wc

Import using the below syntax:

import "scroll-to-top-wc";

Then add the element to your page as below:

<scroll-to-top-wc></scroll-to-top-wc>

Activate When

Use the activatewhen property to determine when the toast notification is shown. This value is in pixels and by default is set to 200. The below will mean we need to scroll down twice as far before the toast notification is shown

<scroll-to-top-wc activatewhen="400"></scroll-to-top-wc>

Customize Display Text

The text displayed by the toast notification can be customised using light DOM nodes as below. Note that we need to specify SLOT='TEXT' for the node that will display the text on the toast notification

<scroll-to-top-wc>
  <div slot="text">Move this to the top3</div>
</scroll-to-top-wc>

Smooth Scrolling:

In order for the page to scroll to the top in a smooth fasion you may need to apply the below CSS to the document body:

scroll-behavior: smooth;

This works automatically in Chrome so no need to add!

Styling

The component can be styled using CSS Shadow Parts. The part 'container' can be selected to allow any CSS to be applied as shown in the below example:

 scroll-to-top-wc::part(container) {
        background: blue;
        border: 5px solid black;
      }

For browsers that do not support CSS Shadow Parts, the below CSS Custom Properties can be set to style a limited part of the component:

--scroll-top-background-color
--scroll-top-color

Fancy Mode!

We can enable the toast that is shown to be a 3D flip card by adding the 'fancy' attribute as below:

<scroll-to-top-wc fancy></scroll-to-top-wc>

Events

At the point of initiating the scroll of the page the component with emit a 'scrolling' event which can be hooked into in order to provide an visual feeback that is required.

window.addEventListener('onscrolling', (e) => {
// add your code here as desired
})

Testing

Run the below it order to open the demo page. This will run the typescript compiler and then use the parcel bundler to open the page

npm run dev