Zurück zum Ranking

callmecavs/jump.js

JavaScriptgithub.com/callmecavs/jump.js

A modern smooth scrolling library.

scrollsmooth
Sterne-Wachstum
Sterne
3.4k
Forks
158
Wochenwachstum
Issues
9
1k2k3k
Juli 2015März 2019Nov. 2022Juli 2026
Artefaktenpmnpm install jump.js
README

Jump.js

Jump.js on NPM Jump.js Downloads on NPM Standard JavaScript Style

A modern smooth scrolling library.

Usage

Jump was developed with a modern JavaScript workflow in mind. To use it, it's recommended you have a build system in place that can transpile ES6, and bundle modules. For a minimal boilerplate that fulfills those requirements, check out outset.

Follow these steps to get started:

  1. Install
  2. Import
  3. Call
  4. Review Options

Install

Using NPM, install Jump, and save it to your package.json dependencies.

$ npm install jump.js --save

Import

Import Jump, naming it according to your preference.

// import Jump

import jump from 'jump.js'

Call

Jump exports a singleton, so there's no need to create an instance. Just call it, passing a target.

// call Jump, passing a target

jump('.target')

Note that the singleton can make an infinite number of jumps.

Options

All options, except target, are optional, and have sensible defaults. The defaults are shown below:

jump('.target', {
  duration: 1000,
  offset: 0,
  callback: undefined,
  easing: easeInOutQuad,
  a11y: false
})

Explanation of each option follows:

target

Scroll from the current position by passing a number of pixels.

// scroll down 100px

jump(100)

// scroll up 100px

jump(-100)

Or, scroll to an element, by passing either:

  • a node, or
  • a CSS selector
// passing a node

const node = document.querySelector('.target')

jump(node)

// passing a CSS selector
// the element referenced by the selector is determined using document.querySelector

jump('.target')

duration

Pass the time the jump() takes, in milliseconds.

jump('.target', {
  duration: 1000
})

Or, pass a function that returns the duration of the jump() in milliseconds. This function is passed the jump() distance, in px, as a parameter.

jump('.target', {
  duration: distance => Math.abs(distance)
})

offset

Offset a jump(), only if to an element, by a number of pixels.

// stop 10px before the top of the element

jump('.target', {
  offset: -10
})

// stop 10px after the top of the element

jump('.target', {
  offset: 10
})

Note that this option is useful for accommodating position: fixed elements.

callback

Pass a function that will be called after the jump() has been completed.

// in both regular and arrow functions, this === window

jump('.target', {
  callback: () => console.log('Jump completed!')
})

easing

Easing function used to transition the jump().

jump('.target', {
  easing: easeInOutQuad
})

See easing.js for the definition of easeInOutQuad, the default easing function. Credit for this function goes to Robert Penner.

a11y

If enabled, and scrolling to an element:

jump('.target', {
  a11y: true
})

Note that this option is disabled by default because it has visual implications in many browsers. Focusing an element triggers the :focus CSS state selector, and is often accompanied by an outline.

Browser Support

Jump depends on the following browser APIs:

Consequently, it supports the following natively:

  • Chrome 24+
  • Firefox 23+
  • Safari 6.1+
  • Opera 15+
  • IE 10+
  • iOS Safari 7.1+
  • Android Browser 4.4+

To add support for older browsers, consider including polyfills/shims for the APIs listed above. There are no plans to include any in the library, in the interest of file size.

License

MIT. © 2017 Michael Cavalea

Built With Love

Ähnliche Repositories
greensock/GSAP

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

JavaScriptnpmanimationgsap
gsap.com
26.9k2.1k
jlmakes/scrollreveal

Animate elements as they scroll into view.

JavaScriptnpmrevealanimation
scrollrevealjs.org
22.5k2.2k
Caldis/Mos

一个用于在 macOS 上平滑你的鼠标滚动效果或单独设置滚动方向的小工具, 让你的滚轮爽如触控板 | A lightweight tool used to smooth scrolling and set scroll direction independently for your mouse on macOS

SwiftOthermousesmooth
mos.caldis.me
20.9k661
darkroomengineering/lenis

Smooth scroll as it should be

TypeScriptnpmMIT Licensescrollsmooth
lenis.dev
14.7k604
noah-nuebling/mac-mouse-fix

Mac Mouse Fix - Make Your $10 Mouse Better Than an Apple Trackpad!

Objective-COthermousemouse-events
macmousefix.com
10.5k373
alexfoxy/lax.js

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

JavaScriptnpmMIT Licenseparallaxscroll
10.5k481
pmndrs/use-gesture

👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.

TypeScriptnpmMIT Licensegestureshooks
use-gesture.netlify.app
9.6k336
SwiftUIX/SwiftUIX

An exhaustive expansion of the standard SwiftUI library.

SwiftMIT Licenseswift-package-managertextview
8.1k496
florent37/MaterialViewPager

A Material Design ViewPager easy to use library

JavaMavenApache License 2.0materialandroid
fiches-plateau-moto.fr
8.1k1.5k
KingSora/OverlayScrollbars

A javascript scrollbar plugin that hides the native scrollbars, provides custom styleable overlay scrollbars, and preserves the native functionality and feel.

TypeScriptnpmMIT Licensescrollbar-pluginjavascript-scrollbar-plugin
kingsora.github.io/OverlayScrollbars
5.2k249
flesler/jquery.scrollTo

Lightweight, cross-browser and highly customizable animated scrolling with jQuery

JavaScriptnpmMIT Licensejqueryscrollto
demos.flesler.com/jquery/scrollTo/
3.7k996
stutrek/scrollmonitor

A simple and fast API to monitor elements as you scroll

TypeScriptnpmMIT Licensescrolldom
3.3k236