Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom scroll container #31

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Apply the withScrolling function to any html-identifier ("div", "ul" etc) or rea
* `verticalStrength` - a function that returns the strength of the vertical scroll direction
* `strengthMultiplier` - strength multiplier, play around with this (default 30)
* `onScrollChange` - a function that is called when `scrollLeft` or `scrollTop` of the component are changed. Called with those two arguments in that order.
* `scrollContainer` - a custom Element to attach event listeners to for scrolling. Defaults to the wrapped react component.

The strength functions are both called with two arguments. An object representing the rectangle occupied by the Scrollzone, and an object representing the coordinates of mouse.

Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function createScrollingComponent(WrappedComponent) {
verticalStrength: PropTypes.func,
horizontalStrength: PropTypes.func,
strengthMultiplier: PropTypes.number,
scrollContainer: PropTypes.instanceOf(typeof Element !== 'undefined' ? Element : Object),
};

static defaultProps = {
Expand All @@ -85,7 +86,7 @@ export default function createScrollingComponent(WrappedComponent) {
}

componentDidMount() {
this.container = findDOMNode(this.wrappedInstance);
this.container = this.props.scrollContainer || findDOMNode(this.wrappedInstance);
this.container.addEventListener('dragover', this.handleEvent);
// touchmove events don't seem to work across siblings, so we unfortunately
// have to attach the listeners to the body
Expand Down