simplescroll

2.1.3 • Public • Published

simplescroll

A very simple inertial scrolling module that puts together easing functions and a timer to smoothly scroll the page to where you want it.

Installation

npm install simplescroll

Usage

Via script tags:

<script src="simplescroll.js"></script>
var simpleScroll = createSimpleScroll({
  d3: d3,
  easingFn: d3.ease('cubic'),
  timer: d3.timer
});
simpleScroll.scrollToElement(document.querySelect('#the-goal'), 500);

Via Browserify:

var d3 = require('d3-selection');
var ease = require('d3-ease');
var timer = require('d3-timer').timer;
var createSimpleScroll = require('simplescroll');

var simpleScroll = createSimpleScroll({
  d3,
  easingFn: ease.easeCubicInOut,
  timer,
  root: document.body
});
simpleScroll.scrollToElement(document.querySelect('#the-goal'), 500);

You can also specify a third marginAboveTargetElement parameter to scrollToElement so that you can have a little head space over the element. e.g. If you pass 20, there will be 20px between the top of the view and the element that has been scrolled to.

Example

Here's an example.

And here's an explanation about how it works.

License

MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i simplescroll

Weekly Downloads

8

Version

2.1.3

License

MIT

Unpacked Size

7.88 kB

Total Files

7

Last publish

Collaborators

  • jimkang