MoveTo
A lightweight (only 1kb gzipped) scroll animation javascript library without any dependency.
Installation
Using npm
$ npm install moveto --save
Using Yarn
$ yarn add moveto
Using Bower
$ bower install moveTo --save
Usage
const moveTo = ; const target = document; moveTo; // Or register a trigger const trigger = document0; moveTo;
Trigger HTML markup
You can pass all options as data attributes with mt
prefix. Option name should be written in kebab case format, for example:
Trigger <!-- Or --> Trigger
Options
The default options are as follows:
tolerance: 0 duration: 800 easing: 'easeOutQuart' container: window
Option | Default | Desctiption |
---|---|---|
tolerance | 0 | The tolerance of the target to be scrolled, can be negative or positive |
duration | 800 | Duration of scrolling, in milliseconds |
easing | easeOutQuart | Ease function name |
container | window | The container been computed and scrolled |
callback | noop | The function to be run after scrolling complete. Target passes as the first argument |
API
move(target, options)
Start scroll animation from current position to the anchor point
target
Type: HTMLElement|Number
Target element/position to be scrolled. Target position is the scrolling distance. It must be negative if the upward movement is desired.
options
Type: Object
Pass custom options.
registerTrigger(trigger, callback)
trigger
Type: HTMLElement
This is the trigger element for starting to scroll when on click.
callback
This is the callback function to be run after the scroll complete. This will overwrite the callback option.
addEaseFunction(name, fn)
Adds custom ease function.
name
Type: String
Ease function name.
fn
Type: Function
Ease function. See Easing Equations for more ease function.
Examples
Pass ease function(s) when creating instance
document;
Working with callback function
document;
Unregister a trigger
document;
Back to top
document;
Back to top!
Development setup
# To install dev dependencies run: $ yarn # Or so if using npm: $ npm install # To start the development server run: $ yarn start # Or so if using npm: $ npm run start # To lint your code run: $ yarn lint # Or so if using npm: $ npm run lint # To make a full new build run: $ yarn build # Or so if using npm: $ npm run build # To run tests: $ yarn test # Or so if using npm: $ npm test
Browser support
It should work in the current stable releases of Chrome, Firefox, Safari as well as IE10 and up. To add support for older browsers, consider including polyfills/shims for the requestAnimationFrame.
License
Copyright (c) 2017 Hasan Aydoğdu. See the LICENSE file for license rights and limitations (MIT).