Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: callmecavs/jump.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.1
Choose a base ref
...
head repository: callmecavs/jump.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 11 commits
  • 13 files changed
  • 1 contributor

Commits on Jan 8, 2017

  1. update dotfiles

    callmecavs committed Jan 8, 2017
    Copy the full SHA
    488493e View commit details
  2. untrack the dist files

    callmecavs committed Jan 8, 2017
    Copy the full SHA
    964972f View commit details
  3. add manual testing file

    callmecavs committed Jan 8, 2017
    Copy the full SHA
    3d6ffd6 View commit details
  4. Copy the full SHA
    b578c3b View commit details
  5. Copy the full SHA
    4fff715 View commit details
  6. Copy the full SHA
    ef76e69 View commit details
  7. update package.json

    callmecavs committed Jan 8, 2017
    Copy the full SHA
    b22d31a View commit details
  8. fix linting errors

    callmecavs committed Jan 8, 2017
    Copy the full SHA
    8aab623 View commit details

Commits on Mar 21, 2017

  1. Copy the full SHA
    306f333 View commit details
  2. Copy the full SHA
    3df81eb View commit details

Commits on Jan 30, 2018

  1. add license

    callmecavs authored Jan 30, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2aa19ab View commit details
Showing with 136 additions and 175 deletions.
  1. +4 −1 .babelrc
  2. +3 −0 .eslintrc
  3. +2 −1 .gitignore
  4. +2 −0 .npmignore
  5. +21 −0 LICENSE.md
  6. +3 −3 README.md
  7. +0 −7 dist/jump.min.js
  8. +0 −117 gulpfile.js
  9. +32 −19 package.json
  10. +24 −0 rollup.config.js
  11. +4 −2 src/easing.js
  12. +25 −25 src/jump.js
  13. +16 −0 test/manual.html
5 changes: 4 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"presets": ["es2015-rollup"]
"presets": [
"es2015-rollup",
"stage-0"
]
}
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "standard"
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
dist
node_modules
*.log
maps
*.map
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!dist/*
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Michael Cavalea

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Jump.js

[![Jump.js on NPM](https://img.shields.io/npm/v/jump.js.svg?style=flat-square)](https://www.npmjs.com/package/jump.js)
[![Jump.js on NPM](https://img.shields.io/npm/v/jump.js.svg?style=flat-square)](https://www.npmjs.com/package/jump.js) [![Jump.js Downloads on NPM](https://img.shields.io/npm/dm/jump.js.svg?style=flat-square)](https://www.npmjs.com/package/jump.js) [![Standard JavaScript Style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)

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

* [Demo Page](http://callmecavs.github.io/jump.js/) (Click the arrows!)

@@ -199,6 +199,6 @@ To add support for older browsers, consider including polyfills/shims for the AP

## License

[MIT](https://opensource.org/licenses/MIT). © 2016 Michael Cavalea
[MIT](https://opensource.org/licenses/MIT). © 2017 Michael Cavalea

[![Built With Love](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)
7 changes: 0 additions & 7 deletions dist/jump.min.js

This file was deleted.

117 changes: 0 additions & 117 deletions gulpfile.js

This file was deleted.

51 changes: 32 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
{
"name": "jump.js",
"version": "1.0.1",
"description": "A small, modern, dependency-free smooth scrolling library.",
"homepage": "https://github.com/callmecavs/jump.js",
"main": "dist/jump.min.js",
"jsnext:main": "src/jump.js",
"description": "A modern smooth scrolling library.",

"author": "Michael Cavalea",
"main": "dist/jump.js",
"module": "dist/jump.module.js",
"jsnext:main": "dist/jump.module.js",

"version": "1.0.2",
"license": "MIT",

"repository": {
"type": "git",
"url": "https://github.com/callmecavs/jump.js.git"
"repository": "callmecavs/jump.js",

"author": {
"name": "Michael Cavalea",
"email": "callmecavs@gmail.com",
"url": "http://callmecavs.com/"
},
"bugs": {
"url": "https://github.com/callmecavs/jump.js/issues"

"scripts": {
"prebuild": "eslint src",
"build": "rollup -c",
"dev": "rollup -c -w -m inline",
"prepublish": "npm run build",
"server": "python -m SimpleHTTPServer 3000"
},

"keywords": [
"smooth",
"scroll"
],

"devDependencies": {
"babel-preset-es2015-rollup": "*",
"browser-sync": "*",
"del": "*",
"gulp": "*",
"node-notifier": "*",
"rollup": "*",
"rollup-plugin-babel": "*",
"rollup-plugin-uglify": "*"
"babel-eslint": "^7.1.1",
"babel-plugin-external-helpers": "^6.18.0",
"babel-preset-es2015-rollup": "^3.0.0",
"babel-preset-stage-0": "^6.16.0",
"eslint": "^3.13.0",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"rollup": "^0.41.1",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-watch": "^3.2.2"
}
}
24 changes: 24 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'

const info = require('./package.json')

const config = {
entry: 'src/jump.js',
plugins: [
resolve(),
babel()
],
targets: [
{
dest: info.main,
format: 'umd',
moduleName: 'Jump'
}, {
dest: info.module,
format: 'es'
}
]
}

export default config
6 changes: 4 additions & 2 deletions src/easing.js
Original file line number Diff line number Diff line change
@@ -3,9 +3,11 @@
// find the rest of his easing functions here: http://robertpenner.com/easing/
// find them exported for ES6 consumption here: https://github.com/jaxgeller/ez.js

export default (t, b, c, d) => {
const easeInOutQuad = (t, b, c, d) => {
t /= d / 2
if(t < 1) return c / 2 * t * t + b
if (t < 1) return c / 2 * t * t + b
t--
return -c / 2 * (t * (t - 2) - 1) + b
}

export default easeInOutQuad
50 changes: 25 additions & 25 deletions src/jump.js
Original file line number Diff line number Diff line change
@@ -25,21 +25,21 @@ const jumper = () => {

// scroll position helper

function location() {
function location () {
return window.scrollY || window.pageYOffset
}

// element offset helper

function top(element) {
function top (element) {
return element.getBoundingClientRect().top + start
}

// rAF loop helper

function loop(timeCurrent) {
function loop (timeCurrent) {
// store time scroll started, if not started already
if(!timeStart) {
if (!timeStart) {
timeStart = timeCurrent
}

@@ -54,18 +54,18 @@ const jumper = () => {

// check progress
timeElapsed < duration
? requestAnimationFrame(loop) // continue scroll loop
: done() // scrolling is done
? window.requestAnimationFrame(loop) // continue scroll loop
: done() // scrolling is done
}

// scroll finished helper

function done() {
function done () {
// account for rAF time rounding inaccuracies
window.scrollTo(0, start + distance)

// if scrolling to an element, and accessibility is enabled
if(element && a11y) {
if (element && a11y) {
// add tabindex indicating programmatic focus
element.setAttribute('tabindex', '-1')

@@ -74,7 +74,7 @@ const jumper = () => {
}

// if it exists, fire the callback
if(typeof callback === 'function') {
if (typeof callback === 'function') {
callback()
}

@@ -84,59 +84,59 @@ const jumper = () => {

// API

function jump(target, options = {}) {
function jump (target, options = {}) {
// resolve options, or use defaults
duration = options.duration || 1000
offset = options.offset || 0
offset = options.offset || 0
callback = options.callback // "undefined" is a suitable default, and won't be called
easing = options.easing || easeInOutQuad
a11y = options.a11y || false
easing = options.easing || easeInOutQuad
a11y = options.a11y || false

// cache starting position
start = location()

// resolve target
switch(typeof target) {
switch (typeof target) {
// scroll from current position
case 'number':
element = undefined // no element to scroll to
a11y = false // make sure accessibility is off
stop = start + target
break
a11y = false // make sure accessibility is off
stop = start + target
break

// scroll to element (node)
// bounding rect is relative to the viewport
case 'object':
element = target
stop = top(element)
break
stop = top(element)
break

// scroll to element (selector)
// bounding rect is relative to the viewport
case 'string':
element = document.querySelector(target)
stop = top(element)
break
stop = top(element)
break
}

// resolve scroll distance, accounting for offset
distance = stop - start + offset

// resolve duration
switch(typeof options.duration) {
switch (typeof options.duration) {
// number in ms
case 'number':
duration = options.duration
break
break

// function passed the distance of the scroll
case 'function':
duration = options.duration(distance)
break
break
}

// start the loop
requestAnimationFrame(loop)
window.requestAnimationFrame(loop)
}

// expose only the jump method
16 changes: 16 additions & 0 deletions test/manual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>

<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script src="../dist/jump.js"></script>
<script>
console.log('Module assigned to window.Jump. Logged below:')
console.log(Jump)
</script>
</body>
</html>