Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,2 +0,0 @@
node_modules
example.js

View File

@@ -1,67 +1,52 @@
var raf = require('rafl')
var E_NOSCROLL = new Error('Element already at target scroll position')
var E_CANCELLED = new Error('Scroll cancelled')
var min = Math.min
function scroll (prop, element, to, options, callback) {
var start = +new Date
var from = element[prop]
var cancelled = false
module.exports = {
left: make('scrollLeft'),
top: make('scrollTop')
}
var ease = inOutSine
var duration = 350
function make (prop) {
return function scroll (el, to, opts, cb) {
opts = opts || {}
if (typeof options === 'function') {
callback = options
}
else {
options = options || {}
ease = options.ease || ease
duration = options.duration || duration
callback = callback || function () {}
}
if (typeof opts == 'function') cb = opts, opts = {}
if (typeof cb != 'function') cb = noop
if (from === to) {
return callback(
new Error('Element already at target scroll position'),
element[prop]
)
}
var start = +new Date
var from = el[prop]
var ease = opts.ease || inOutSine
var duration = !isNaN(opts.duration) ? +opts.duration : 350
var cancelled = false
function cancel () {
cancelled = true
}
return from === to ?
cb(E_NOSCROLL, el[prop]) :
raf(animate), cancel
function animate (timestamp) {
if (cancelled) {
return callback(
new Error('Scroll cancelled'),
element[prop]
)
function cancel () {
cancelled = true
}
var now = +new Date
var time = Math.min(1, ((now - start) / duration))
var eased = ease(time)
function animate (timestamp) {
if (cancelled) return cb(E_CANCELLED, el[prop])
element[prop] = (eased * (to - from)) + from
var now = +new Date
var time = min(1, ((now - start) / duration))
var eased = ease(time)
time < 1 ? raf(animate) : raf(function () {
callback(null, element[prop])
})
el[prop] = (eased * (to - from)) + from
time < 1 ? raf(animate) : raf(function () {
cb(null, el[prop])
})
}
}
raf(animate)
return cancel
}
function inOutSine (n) {
return .5 * (1 - Math.cos(Math.PI * n))
return 0.5 * (1 - Math.cos(Math.PI * n))
}
module.exports = {
top: function (element, to, options, callback) {
return scroll('scrollTop', element, to, options, callback)
},
left: function (element, to, options, callback) {
return scroll('scrollLeft', element, to, options, callback)
}
}
function noop () {}

View File

@@ -1,43 +1,61 @@
{
"name": "scroll",
"version": "2.0.1",
"description": "A function that animates an elements scrollTop or scrollLeft position.",
"main": "index.js",
"_args": [
[
"scroll@2.0.3",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
]
],
"_from": "scroll@2.0.3",
"_id": "scroll@2.0.3",
"_inBundle": false,
"_integrity": "sha512-3ncZzf8gUW739h3LeS68nSssO60O+GGjT3SxzgofQmT8PIoyHzebql9HHPJopZX8iT6TKOdwaWFMqL6LzUN3DQ==",
"_location": "/material-ui/scroll",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "scroll@2.0.3",
"name": "scroll",
"escapedName": "scroll",
"rawSpec": "2.0.3",
"saveSpec": null,
"fetchSpec": "2.0.3"
},
"_requiredBy": [
"/material-ui"
],
"_resolved": "https://registry.npmjs.org/scroll/-/scroll-2.0.3.tgz",
"_spec": "2.0.3",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
"author": {
"name": "Michael Rhodes"
},
"bugs": {
"url": "https://github.com/michaelrhodes/scroll/issues"
},
"dependencies": {
"rafl": "~1.2.1"
},
"description": "A function that animates an elements scrollTop or scrollLeft position.",
"devDependencies": {
"ease-component": "~1.0.0",
"tape": "~2.3.2"
},
"scripts": {
"test": "tape test/*.js"
},
"testling": {
"files": "test/*.js",
"browsers": {
"ie": [6, 7, 8, 9, 10],
"chrome": [20, 25, 29],
"firefox": [3, 4, 7, 19, 24],
"safari": [5.1, 6],
"opera": [10, 12, 15],
"iphone": [6],
"android": [4.2]
}
},
"repository": {
"type": "git",
"url": "git@github.com:michaelrhodes/scroll.git"
},
"keywords": [
"homepage": "https://github.com/michaelrhodes/scroll#readme",
"keyword": [
"scrollTop",
"scrollTo",
"animate"
],
"author": "Michael Rhodes",
"license": "MIT",
"bugs": {
"url": "https://github.com/michaelrhodes/scroll/issues"
"main": "index.js",
"name": "scroll",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/michaelrhodes/scroll.git"
},
"homepage": "https://github.com/michaelrhodes/scroll"
"scripts": {
"test": "tape test.js"
},
"version": "2.0.3"
}

View File

@@ -4,20 +4,13 @@ A function that animates an elements scrollTop or scrollLeft position.
[![Browser support](https://ci.testling.com/michaelrhodes/scroll.png)](https://ci.testling.com/michaelrhodes/scroll)
| compression | size |
| :--------------- | ------: |
| scroll.js | 2.6 kB |
| scroll.min.js | 1.47 kB |
| scroll.min.js.gz | 700 B |
## Install
## install
```sh
$ npm install scroll
```
### Usage
## use
```js
var scroll = require('scroll')
@@ -28,28 +21,28 @@ var ease = require('ease-component')
scroll.left(page, 200)
// Register a callback
scroll.top(page, 200, function (error, scrollTop) {
console.log(error)
scroll.top(page, 200, function (err, scrollTop) {
console.log(err)
// { message: "Scroll cancelled" } or
// { message: "Element already at target scroll position" } or
// null
console.log(scrollTop)
// => The new scrollTop position of the element
// This is always returned, even when theres an `error`.
// This is always returned, even when theres an `err`.
})
// Specify a custom easing function
scroll.left(page, 200, { ease: ease.inBounce })
// Specify a duration in milliseconds (default: 350) and register a callback.
scroll.left(page, 200, { duration: 1000 }, function (error, scrollLeft) {
scroll.left(page, 200, { duration: 1000 }, function (err, scrollLeft) {
})
// Cancel a scroll animation
// Cancel a scroll animation
var options = { duration: 1000 }
var cancel = scroll.top(page, 200, options, function (error, scrollTop) {
console.log(error.message)
var cancel = scroll.top(page, 200, options, function (err, scrollTop) {
console.log(err.message)
// => Scroll cancelled
page.removeEventListener('wheel', cancel)
@@ -60,6 +53,13 @@ page.addEventListener('wheel', cancel)
Note: The default easing is `inOutSine` from [component/ease](https://github.com/component/ease).
### License
| compression | size |
| :--------------- | ------: |
| scroll.js | 2.86 kB |
| scroll.min.js | 1.71 kB |
| scroll.min.js.gz | 764 B |
## obey
[MIT](http://opensource.org/licenses/MIT)

View File

@@ -1,6 +1,6 @@
var run = require('tape')
var ease = require('ease-component')
var scroll = require('../')
var scroll = require('./')
var container = document.createElement('div')
var box = document.createElement('div')