Code Monkey home page Code Monkey logo

naturalscroll's Introduction

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):

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 and unpack the distribution, or install it using Bower:

$ bower install natural-scroll

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.