react-lite-misc
Version:
Misc Components of jianliao.com
59 lines (52 loc) • 1.44 kB
JavaScript
(function() {
var React, T, debounce, div;
React = require('react');
debounce = require('../util/debounce');
div = React.createFactory('div');
T = React.PropTypes;
module.exports = React.createClass({
displayName: 'wheeling',
propTypes: {
delay: T.number,
onScroll: T.func.isRequired
},
getDefaultProps: function() {
return {
delay: 400
};
},
componentDidMount: function() {
this._rootEl = this.refs.root;
this._wasGoingUp = false;
this._wasGoingDown = false;
return this.debounceDetect = debounce(this.detect, this.props.delay);
},
onWheel: function(event) {
if (event.deltaY > 0) {
this._wasGoingUp = false;
this._wasGoingDown = true;
} else if (event.deltaY < 0) {
this._wasGoingUp = true;
this._wasGoingDown = false;
}
return this.debounceDetect();
},
detect: function() {
var info;
info = {
atTop: this._rootEl.scrollTop === 0,
atBottom: (this._rootEl.scrollTop + this._rootEl.clientHeight) === this._rootEl.scrollHeight,
goingUp: this._wasGoingUp,
goingDown: this._wasGoingDown
};
return this.props.onScroll(info);
},
render: function() {
return div({
ref: 'root',
className: 'wheeling',
onWheel: this.onWheel
}, this.props.children);
}
});
}).call(this);