Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/lib/Scrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { isEqual, debounce } from './helpers'

export default class Scrollable extends React.Component {
componentWillReceiveProps = n => {

if (n.scrollTop !== this.props.scrollTop) {
this.e.scrollTop = n.scrollTop
if (this.props.horizontal) {
this.e.scrollLeft = n.scrollTop
} else {
this.e.scrollTop = n.scrollTop
}
}
if (n.disable !== this.props.disable) {
if (n.disable) this.e.style.pointerEvents = 'none'
Expand All @@ -22,10 +27,15 @@ export default class Scrollable extends React.Component {
this.propagateScroll(e)
}
propagateScroll = debounce(() => {
this.props.onScroll(this.e.scrollTop)

if (this.props.horizontal) {
this.props.onScroll(this.e.scrollLeft);
} else {
this.props.onScroll(this.e.scrollTop);
}
})
render() {
const { children, height, className } = this.props
const { children, height, className, horizontal } = this.props
return (
<div
style={{
Expand Down
9 changes: 7 additions & 2 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export default class MotionScroll extends React.Component {
if (this.state.scroll !== to) {
if (typeof to === 'number') this.fire(to)
if (typeof to === 'string') {
this.fire(document.getElementById(to).offsetTop)
if (this.props.horizontal) {
this.fire(document.getElementById(to).offsetLeft)
} else {
this.fire(document.getElementById(to).offsetTop)
}
}
}
}
Expand All @@ -28,7 +32,7 @@ export default class MotionScroll extends React.Component {

render() {
const { scrollTo, props, state } = this
const { children, height, className, onScroll, config } = props
const { children, height, className, onScroll, horizontal, config } = props
const { scroll, fire } = state
return (
<Motion
Expand All @@ -45,6 +49,7 @@ export default class MotionScroll extends React.Component {
height={height}
disable={this.state.fire}
scrollTop={m.x}
horizontal={horizontal}
onScroll={this.set('scroll')}
children={React.cloneElement(children, { scrollTo })}
/>}
Expand Down