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

animated-scroll

v0.0.3

Published

Animate scrollTop and scrollLeft

Downloads

50

Readme

animated-scroll

Greenkeeper badge Build Status Licence Coverage Status Bower version npm version

Allows animating scrollTop and/or scrollLeft of an HTML element. Uses requestAnimationFrame to provide smooth animations and returns a Promise to notify when the animation is completed.

Installation

Install with bower:

bower install animated-scroll

Or with npm:

npm install animated-scroll

Or simply download the latest release.

Usage

The pre-built files can be found in the dist/ directory. dist/AnimatedScroll.min.js is minified and production-ready. It has a UMD wrapper so you can access it as:

var AnimatedScroll = require('animated-scroll');
// or
import AnimatedScroll from 'animated-scroll';
// or
define([ 'path/to/animated-scroll' ], function (AnimatedScroll) {});
// or
var AnimatedScroll = window.AnimatedScroll;

Example

var element = document.getElementById('myElement');
var scroll = new AnimatedScroll(element);

scroll.top(100).then(function (newTop) {
    // newTop === 100
    console.log('#myElement\'s scrollTop is now', newTop);
});

scroll.left(100).then(function (newLeft) {
    // newLeft === 100
    console.log('#myElement\'s scrollLeft is now', newLeft);
});

scroll.to({ left: 100, top: 100 }).then(function (coords) {
    console.log('#myElement\'s scrollTop is now', coords.top);
    console.log('#myElement\'s scrollLeft is now', coords.left);
});

API

AnimatedScroll.prototype.top(top [, duration [, easing]]) : Promise

Animates the scrollTop of element from it's current scrollTop to the new scrollTop in a time-frame of duration and using the provided easing function (duration and easing are optional).

It returns a promise which is resolved with the value of the new scrollTop when the animation is complete.

duration is in milliseconds and defaults to 400 if not provided. If set to 0 or false, then the scrollTop is set without animating. In this case an already fulfilled promise is returned.

If no easing is provided and duration is provided then the default easing function used is easeInOutQuad.

Calling .top on an element while a scrollTop animation is currently ongoing will stop that animation and start a new one i.e. animations are not queued. You can queue animations by hooking into the .then of the returned promise.

AnimatedScroll.prototype.left(top [, duration [, easing]]) : Promise

Exactly the same as .top but for scrollLeft :)

AnimatedScroll.prototype.to({ top, left } [, duration [, easing]]) : Promise

Convinient way to animate both scrollTop and scrollLeft. Accepts an object with top and left properties and returns a promise which resolves with an object containing the new top and left values.

AnimatedScroll.prototype.stopTop() : undefined

Stops any currently-running animation of scrollTop.

AnimatedScroll.prototype.stopLeft() : undefined

Stops any currently-running animation of scrollLeft.

AnimatedScroll.prototype.stop() : undefined

Stops any currently-running animation of scrollLeft or scrollTop.

Contributing

Contributions are welcomed! Here are the contribution guidelines.

First clone the repository and install dependencies:

npm install

To run tests:

npm test

To lint the code:

npm run lint

To make a production build:

npm run build

License

The MIT License