GithubHelp home page GithubHelp logo

albertolarah / jump.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from callmecavs/jump.js

0.0 2.0 0.0 60 KB

A small, modern, dependency-free smooth scrolling library.

Home Page: http://callmecavs.github.io/jump.js/

License: MIT License

JavaScript 100.00%

jump.js's Introduction

Jump.js

Jump.js on NPM

A small, modern, dependency-free 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:

Install

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

$ npm install jump.js --save

Instantiate

Simply import Jump, then instantiate it. No options are passed to the constructor.

// import Jump
import Jump from 'jump.js'

// create an instance
const Jump = new Jump()

It's recommended that you assign your Jump instance to a variable. One instance can make infinite jumps.

Jump

Two parameters are required to make a jump:

Target

To jump to an element, pass a CSS selector as a string.

Jump.jump('.selector', {
  // options...
})

To scroll from the current position, pass a number of pixels, positive or negative.

// down one viewport height
Jump.jump(window.innerHeight, {
  // options...
})

// up 100px
Jump.jump(-100, {
  // options...
})

Options

Note that duration is required for every jump().

Defaults are shown below, explanation of each option follows.

Jump.jump('.selector', {
  duration: /* REQUIRED, no default */,
  offset: 0,
  callback: undefined,
  easing: (t, b, c, d) => {
    // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
    t /= d / 2
    if(t < 1) return c / 2 * t * t + b
    t--
    return -c / 2 * (t * (t - 2) - 1) + b
  }
})
duration

How long the jump() takes, in milliseconds.

Jump.jump('.selector', {
  duration: 1000
})

Or, a function accepting distance (in px) as an argument, and returning the duration (in milliseconds) as a number.

Jump.jump('.selector', {
  duration: (distance) => Math.abs(distance)
})
offset

Offset a jump(), only if to an element, in pixels.

Useful for accomodating elements fixed to the top/bottom of the screen.

Jump.jump('.selector', {
  offset: 100
})
callback

Fired after the jump() has been completed.

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

Easing function used to transition the jump().

Jump.jump('.selector', {
  easing: (t, b, c, d) => {
    return c * (t /= d) * t + b
  }
})

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. © 2015 Michael Cavalea

Built With Love

jump.js's People

Contributors

callmecavs avatar timpetricola avatar artemdemo avatar iduuck avatar

Watchers

Alberto Lara Hernández avatar  avatar

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.