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-vertical

v1.1.4

Published

scroll to element or position

Downloads

90

Readme

scroll-to-vertical

Smooth scroll to element or position at page. Takes into account document height for elements low on the page.

Features

  • ~5 KB
  • no dependencies
  • scrolling - bottom, top
  • specify the amount in pixels that needs to be scrolled
  • scroll to an element

Installation

npm install scroll-to-vertical --save

Or you can load it via a script tag as follows:

<script src="https://unpkg.com/scroll-to-vertical" />

Importing

ES6

import ScrollToVertical from 'scroll-to-vertical';

CommonJS

var ScrollToVertical = require('scroll-to-vertical');

Global variable

the variable ScrollToVertical attached to window or this depending on what environment you are using

API

new ScrollToVertical(selector, <options>)

| Property | Value | | ---------------------- | ------------------------------------------------------------- | | selector:string(required) | css selector | | OPTIONS:| | | isBehavior:boolean | default: true use native window.scrollTo (if the browser supports) | | behavior:string | default: smooth option for window.scrollTo smooth, instant, auto | | typeToScroll:string or number or function | default: string: href string - name of the attribute where the selector of the element to which scrolling should lie example: href, data-href... number - position on the page where you want to scroll example: 0 - to scroll up function - triggered by every event. Returns the number. Point to scroll to example: return document.documentElement.scrollHeight - to scroll bottom page | | step:number | default: 50 number of pixels scrolled at a time | | typeToScrollAdd:number | default: 0 indent for the end point of the scroll | | eventType:string | default: click event: 'click', 'mouseover' ... | | Callbacks | | | loadCallback | callback function that is called upon initialization parameters: this - instance class | | startEventCallback | callback function that is called before eventType (click) parameters: event, this, element, endScrollPosition | | beforeAnimationCallback | callback function that is called before start animation parameters: this, element, endScrollPosition | | afterAnimationCallback | callback function that is called after finish animation* *not working on native window.scrollTo (isBehavior=true) parameters: this - instance class | | Methods | | | simulationScroll | scrolls to the desired (dynamic) point takes two parameters a scroll point (number, selector or DOM ELEMENT) and indent for the end point of the scroll |

Example Usage

import ScrollToVertical from 'scroll-to-vertical';

new ScrollToVertical('.js_link_nav_scroll', {
    eventType: 'click',
    behavior: "smooth",
    typeToScroll: 20,
    beforeAnimationCallback: function (that, $el, endPosition) {
        console.group('beforeAnimationCallback');
        console.log(that);
        console.log($el);
        console.log(endPosition);
        console.groupEnd();
    }
})

default (no settings)

Click on the link. Scroll to the element whose selector is registered in the href

<a class="js_link_nav_scroll" href="#section_1">scroll to section_1</a>
<div id="#section_1"></div>

<script>  
    new ScrollToVertical('.js_link_nav_scroll');
</script>

Dynamic value - method simulationScroll

<script>  
    const simulateScroll = new  ScrollToVertical('empty');
    /** scroll to the point */
    setTimeout(() => {
        simulateScroll.simulationScroll(1120)
    }, 1000);
    setTimeout(() => {
        /** scroll to the DOM element (by selector). And indent for the end point of the scroll */
        simulateScroll.simulationScroll('#content', -50)
    }, 2000);
    setTimeout(() => {
        /** scroll to the DOM element (by DOM ELEMENT). And indent for the end point of the scroll */
        simulateScroll.simulationScroll(document.getElementById('content'), -50)
    }, 3000);
</script>

Browser Support

Supported on all modern browsers. For older browsers, you would need the polyfills for requestAnimationFrame.