All Projects → hsnaydd → Moveto

hsnaydd / Moveto

Licence: mit
A lightweight scroll animation javascript library without any dependency

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Moveto

really-smooth-scroll
A script that smoothen scrolling in the browser
Stars: ✭ 21 (-99.24%)
Mutual labels:  scrolling, scroll, smooth-scrolling
Horizontal Scroll
Horizontal scroll with inertia
Stars: ✭ 175 (-93.63%)
Mutual labels:  scroll, scrolling, smooth
universalSmoothScroll
A cross-browser smooth-scrolling API which supports multiple and interruptable scroll-animations on all DOM's elements, even at the same time!
Stars: ✭ 46 (-98.32%)
Mutual labels:  scroll, smooth, scroll-animations
Ngx Scroll To
Scroll to any element to enhance scroll-based features in you app. Works for Angular 4+, both AoT and SSR. No dependencies.
Stars: ✭ 269 (-90.2%)
Mutual labels:  scroll, scrolling, smooth-scrolling
Mac Mouse Fix
Mac Mouse Fix - A simple way to make your mouse better.
Stars: ✭ 362 (-86.82%)
Mutual labels:  scroll, scrolling, smooth-scrolling
Scroll Into View If Needed
Element.scrollIntoView ponyfills for things like "if-needed" and "smooth"
Stars: ✭ 811 (-70.47%)
Mutual labels:  scrolling, smooth-scrolling, smooth
Scrollissimo
Javascript plugin for smooth scroll-controlled animations
Stars: ✭ 160 (-94.17%)
Mutual labels:  scrolling, smooth-scrolling, smooth
Jump.js
A modern smooth scrolling library.
Stars: ✭ 3,459 (+25.97%)
Mutual labels:  scroll, scrolling, smooth
Ngx Scrollbar
Custom overlay-scrollbars with native scrolling mechanism
Stars: ✭ 355 (-87.07%)
Mutual labels:  scroll, smooth-scrolling, smooth
Mos
一个用于在 macOS 上平滑你的鼠标滚动效果或单独设置滚动方向的小工具, 让你的滚轮爽如触控板 | A lightweight tool used to smooth scrolling and set scroll direction independently for your mouse on macOS
Stars: ✭ 7,772 (+183.03%)
Mutual labels:  scroll, smooth-scrolling, smooth
React Indiana Drag Scroll
React component which implements scrolling via holding the mouse button or touch
Stars: ✭ 190 (-93.08%)
Mutual labels:  lightweight, scroll, scrolling
Core Components
Accessible and lightweight Javascript components
Stars: ✭ 85 (-96.9%)
Mutual labels:  lightweight, scroll
Smoothscrollanimations
Demo of a tutorial on how to add smooth page scrolling with an inner image animation
Stars: ✭ 238 (-91.33%)
Mutual labels:  scrolling, smooth-scrolling
Easy Scroll
A lightweight native javascript library to perform smooth scrolling with animation
Stars: ✭ 96 (-96.5%)
Mutual labels:  scrolling, smooth-scrolling
Prognroll
A tiny, lightweight jQuery plugin that creates scroll progress bar on the page.
Stars: ✭ 108 (-96.07%)
Mutual labels:  scroll, scrolling
Scroll Behavior Polyfill
A polyfill for the 'scroll-behavior' CSS-property
Stars: ✭ 76 (-97.23%)
Mutual labels:  smooth-scrolling, smooth
Pd Select
vue components ,like ios 3D picker style,vue 3d 选择器组件,3D滚轮
Stars: ✭ 101 (-96.32%)
Mutual labels:  scroll, scrolling
Jquery Scrolllock
Locks mouse wheel scroll inside container, preventing it from propagating to parent element
Stars: ✭ 109 (-96.03%)
Mutual labels:  scroll, scrolling
Dragscroll
micro library for drag-n-drop scrolling style
Stars: ✭ 989 (-63.98%)
Mutual labels:  scroll, scrolling
Rolly
Custom scroll with inertia, smooth parallax and scenes manager
Stars: ✭ 109 (-96.03%)
Mutual labels:  scroll, smooth-scrolling

MoveTo Version CDNJS version CI Status

A lightweight (only 1kb gzipped) scroll animation javascript library without any dependency.

Demo

Installation

Using npm

$ npm install moveto --save

Using Yarn

$ yarn add moveto

Usage

const moveTo = new MoveTo();

const target = document.getElementById('target');

moveTo.move(target);

// Or register a trigger

const trigger = document.getElementsByClassName('js-trigger')[0];

moveTo.registerTrigger(trigger);

Trigger HTML markup

You can pass all options as data attributes with the mt prefix. Option name should be written in kebab case format, for example:

<a href="#target" class="js-trigger" data-mt-duration="300">Trigger</a>

<!-- Or -->

<button type="button" class="js-trigger" data-target="#target" data-mt-duration="300">Trigger</button>

Options

The following options are available:

new MoveTo({
  tolerance: 0,
  duration: 800,
  easing: 'easeOutQuart',
  container: window
})
Option Default Description
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 ran after the scroll completes. 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 functions.

Examples

Pass ease function(s) when creating an instance
document.addEventListener('DOMContentLoaded', function () {
  const easeFunctions = {
    easeInQuad: function (t, b, c, d) {
      t /= d;
      return c * t * t + b;
    },
    easeOutQuad: function (t, b, c, d) {
      t /= d;
      return -c * t* (t - 2) + b;
    }
  }

  const moveTo = new MoveTo({
    duration: 1000,
    easing: 'easeInQuad'
  }, easeFunctions);

  const trigger = document.getElementsByClassName('js-trigger')[0];

  moveTo.registerTrigger(trigger);
});
Working with callback function
document.addEventListener('DOMContentLoaded', function () {
  const moveTo = new MoveTo({
    duration: 1000,
    callback: function (target) {
      // This will run if there is no overwrite
    }
  });

  const trigger = document.getElementsByClassName('js-trigger')[0];

  moveTo.registerTrigger(trigger, function (target) {
    // Overwrites global callback
  });

  // Or

  moveTo.move(1200, {
    duration: 500,
    callback: function () {
      // Overwrites global callback
    }
  });
});
Unregister a trigger
document.addEventListener('DOMContentLoaded', function () {
  const moveTo = new MoveTo();

  const trigger = document.getElementsByClassName('js-trigger')[0];

  // Register a trigger
  const unregister = moveTo.registerTrigger(trigger, { duration: 500 });

  // Unregister a trigger
  unregister();
});
Back to top
document.addEventListener('DOMContentLoaded', function () {
  const moveTo = new MoveTo();
  const triggers = document.getElementsByClassName('js-back-to-top');

  for (var i = 0; triggers.length < i; i++) {
    moveTo.registerTrigger(triggers[i]);
  }
});
<a href="#" class="js-back-to-top" data-mt-duration="300">Back to top!</a>

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 and Edge. To add support for older browsers, consider including polyfills/shims for the requestAnimationFrame and Element.scroll.

License

Copyright (c) 2017 Hasan Aydoğdu. See the LICENSE file for license rights and limitations (MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].