Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

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

View File

@@ -0,0 +1,67 @@
var raf = require('rafl')
function scroll (prop, element, to, options, callback) {
var start = +new Date
var from = element[prop]
var cancelled = false
var ease = inOutSine
var duration = 350
if (typeof options === 'function') {
callback = options
}
else {
options = options || {}
ease = options.ease || ease
duration = options.duration || duration
callback = callback || function () {}
}
if (from === to) {
return callback(
new Error('Element already at target scroll position'),
element[prop]
)
}
function cancel () {
cancelled = true
}
function animate (timestamp) {
if (cancelled) {
return callback(
new Error('Scroll cancelled'),
element[prop]
)
}
var now = +new Date
var time = Math.min(1, ((now - start) / duration))
var eased = ease(time)
element[prop] = (eased * (to - from)) + from
time < 1 ? raf(animate) : raf(function () {
callback(null, element[prop])
})
}
raf(animate)
return cancel
}
function inOutSine (n) {
return .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)
}
}

View File

@@ -0,0 +1,100 @@
{
"_args": [
[
"scroll@2.0.1",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "scroll@2.0.1",
"_id": "scroll@2.0.1",
"_inBundle": false,
"_integrity": "sha1-tMfSfovPOuiligQvJyaK4/VfnM0=",
"_location": "/material-ui/scroll",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "scroll@2.0.1",
"name": "scroll",
"escapedName": "scroll",
"rawSpec": "2.0.1",
"saveSpec": null,
"fetchSpec": "2.0.1"
},
"_requiredBy": [
"/material-ui"
],
"_resolved": "https://registry.npmjs.org/scroll/-/scroll-2.0.1.tgz",
"_spec": "2.0.1",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"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"
},
"homepage": "https://github.com/michaelrhodes/scroll",
"keywords": [
"scrollTop",
"scrollTo",
"animate"
],
"license": "MIT",
"main": "index.js",
"name": "scroll",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/michaelrhodes/scroll.git"
},
"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
]
}
},
"version": "2.0.1"
}

View File

@@ -0,0 +1,65 @@
# scroll
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
```sh
$ npm install scroll
```
### Usage
```js
var scroll = require('scroll')
var page = require('scroll-doc')()
var ease = require('ease-component')
// Basic usage
scroll.left(page, 200)
// Register a callback
scroll.top(page, 200, function (error, scrollTop) {
console.log(error)
// { 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`.
})
// 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) {
})
// Cancel a scroll animation
var options = { duration: 1000 }
var cancel = scroll.top(page, 200, options, function (error, scrollTop) {
console.log(error.message)
// => Scroll cancelled
page.removeEventListener('wheel', cancel)
})
page.addEventListener('wheel', cancel)
```
Note: The default easing is `inOutSine` from [component/ease](https://github.com/component/ease).
### License
[MIT](http://opensource.org/licenses/MIT)

View File

@@ -0,0 +1,81 @@
var run = require('tape')
var ease = require('ease-component')
var scroll = require('../')
var container = document.createElement('div')
var box = document.createElement('div')
container.style.cssText = [
'height: 100px',
'outline: 1px solid #000',
'overflow: scroll',
'width: 100px'
].join(';')
box.style.cssText = [
'outline: 1px solid #888',
'height: 50px',
'width: 300px'
].join(';')
var n = 50
while (--n) {
container.appendChild(box.cloneNode(true))
}
document.body.appendChild(container)
run('it scrolls', function (test) {
container.scrollTop = 0
container.scrollLeft = 200
test.plan(3)
scroll.top(container, 200, function (error, position) {
test.ok(position === 200, 'it scrolled down 200 pixels')
scroll.top(container, 200, function (error, position) {
test.equal(error.message, 'Element already at target scroll position')
})
})
var leftOptions = { duration: 1000, ease: ease.inBounce }
scroll.left(container, -200, leftOptions, function (error, position) {
test.ok(position === 0, 'it scrolled across 200 pixels')
})
})
run('it can be cancelled', function (test) {
container.scrollTop = 0
container.scrollLeft = 200
test.plan(2)
var options = { duration: 1000, ease: ease.inBounce }
var cancel = scroll.left(container, -200, options,
function (error, position) {
test.ok(error, 'it produced an error')
test.equal(error.message, 'Scroll cancelled', 'it cancelled the animation')
})
setTimeout(cancel, 500)
})
run('callback fires after scroll events', function (test) {
container.scrollTop = 0
test.plan(1)
var okay = true
var done = false
container.addEventListener('scroll', function () {
if (done) okay = false
}, false)
scroll.top(container, 200, function () {
done = true
setTimeout(function () {
test.ok(okay, 'callback fired after scroll events')
}, 100)
})
})