Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

natural-scroll

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

natural-scroll

smoothly and prgramatically scrolls the viewport to the desired position

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

natural scroll

Objects in real life never stop or start moving instantly. Having this in mind, natural scroll performs scrolling smoothly and naturally: it starts and finishes the movement with zero speed and acceleration. If another scrolling target is specified during an animation still running, natural scroll recalculates the remaining animation frames, so that the scrolling continues smoothly and reaches the new destination. The slowdowns and accelerations do not make the animation look slower. The scrolling just feels better. A user may not even notice the magic at all, but a good design should not be noticed. For him the scrolling becomes natural, comfortable and predictable.

You can see how natural scroll works on the following web-pages (click the menu items there and carefully watch how the page is scrolled):

  • Home page of the intence project

  • Demo page for the viewport.js library

natural scroll has flexible FPS. Which means if a system is too slow (or a web-page is too overdesigned), natural scroll skips some of the frames, preserving the total time of animation. Therefore the destination scrolling position is reached on time and users do not have to wait any longer. Of course on faster systems the animation is more fluent.

natural scroll does not have any dependencies, it is written in vanilla javascript which means it works anywhere. And it only costs 748 bytes of minified code including the UMD-headers!

Usage

Using natural scroll is very simple. Download the distribution, unpack it and load the naturalScroll.js module in a preferable way:

<script src="naturalScroll.js"></script>

Invoke the following methods to scroll a viewport to the desired position:

// element to scroll, can be document.body
var viewport = document.getElementById('myViewport');
var positionTop = 1000;
var positionLeft = 500;

naturalScroll.scrollTop(viewport, positionTop);
naturalScroll.scrollLeft(viewport, positionLeft);

You can also provide the third argument which is an animation time (in msec, 600 by default), but I would not change it.

Have fun!

follow me on twitter: https://twitter.com/asvd0

Keywords

FAQs

Package last updated on 20 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc