├── .gitignore
├── LICENSE
├── README.md
├── index.js
├── package.json
└── src
└── Bouncefix.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Deployed apps should consider commenting this line out:
24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
25 | node_modules
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 BigDatr Pty Ltd
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
24 |
25 | The MIT License (MIT) Copyright (c) 2013 Jarid Margolin
26 |
27 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
28 |
29 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
30 |
31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | react-bouncefix
2 | ===============
3 |
4 | A [ReactJS](http://facebook.github.io/react/) component which stops elastic bouncing from moving the entire page(body) when scrollable element has reached the extremes.
5 |
6 |
7 |
8 | Credit
9 | -------
10 | This is a ReactJS implementation of [@jaridmargolin](https://github.com/jaridmargolin)'s [bouncefix.js](http://jaridmargolin.github.io/bouncefix.js/)
11 |
12 |
13 | Why?
14 | ----
15 |
16 | IOS (since IOS 5) offers native touch scrolling within nested containers via `-webkit-overflow-scrolling: touch;`, however, if scrolling occurs at one of the extremes, top or bottom, the elastic bounce occurs on the page rather than the nested container. `bouncefix.js` offers a viable solution to fix this issue. `react-bouncefix` is a reuseable component for ReactJS based applications
17 |
18 | **note:** If there is no content to scroll, scrolling is blocked on the container. This may cause issues if attempting to implement a scroll to refresh feature. This can be overcome creating a wrapper inside of your container and setting the height to 100% with a top and bottom padding of 1px (Not perfect, hackish, but it works)
19 |
20 | ##Install
21 |
22 | npm install react-bouncefix
23 |
24 | ##Example
25 | For documentation on how to use react, check out http://facebook.github.io/react/docs/getting-started.html
26 |
27 |
28 | ####For projects using JSX
29 | ```js
30 | /** @jsx React.DOM */
31 | var Bouncefix = require('react-bouncefix');
32 |
33 | var MyComponent = React.createClass({
34 | render: function() {
35 | return (
36 |
37 | Hello from MyComponent!
38 |
39 | );
40 | }
41 | });
42 |
43 |
44 | React.renderComponent(
45 | MyComponent,
46 | document.getElementById('container')
47 | );
48 |
49 | ```
50 |
51 |
52 |
53 | Add to your css
54 |
55 | ```css
56 | .Bouncefix {
57 | overflow-y: auto;
58 | overflow-x: hidden;
59 | -webkit-overflow-scrolling: touch;
60 | }
61 |
62 | ```
63 |
64 | ##Parameters
65 |
66 | #####component
67 | By default this will be a `div`, however, you may specify any React supported element. See http://facebook.github.io/react/docs/tags-and-attributes.html#html-elements
68 |
69 | ```js
70 |
71 | Hello from MyComponent!
72 |
73 |
74 | ```
75 |
76 |
77 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./src/Bouncefix');
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-bouncefix",
3 | "version": "1.0.5",
4 | "description": "A ReactJS component to stop elastic bouncing on body",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git://github.com/bigdatr/react-bouncefix.git"
12 | },
13 | "author": "Atridge D'Costa ",
14 | "license": "MIT",
15 | "bugs": {
16 | "url": "https://github.com/bigdatr/react-bouncefix/issues"
17 | },
18 | "homepage": "https://github.com/bigdatr/react-bouncefix",
19 | "devDependencies": {
20 | "object-assign": "^4.0.1"
21 | },
22 | "peerDependencies": {
23 | "react": ">=0.12.2"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Bouncefix.js:
--------------------------------------------------------------------------------
1 | var React = require('react');
2 | var ReactDOM = require('react-dom');
3 | var assign = require('object-assign');
4 |
5 | var Bouncefix = React.createClass({
6 | displayName: 'Bouncefix',
7 | propTypes: {
8 | componentClass: React.PropTypes.node
9 | },
10 | getDefaultProps: function() {
11 | return {
12 | componentClass: 'div'
13 | };
14 | },
15 | scrollToEnd: function(el) {
16 | var curPos = el.scrollTop,
17 | height = el.offsetHeight,
18 | scroll = el.scrollHeight;
19 |
20 | // If at top, bump down 1px
21 | if(curPos <= 0) { el.scrollTop = 1; }
22 |
23 | // If at bottom, bump up 1px
24 | if(curPos + height >= scroll) {
25 | el.scrollTop = scroll - height - 1;
26 | }
27 | },
28 | onTouchStart: function(e) {
29 | var el = ReactDOM.findDOMNode(this);
30 | var isScrollable = el.scrollHeight > el.offsetHeight;
31 |
32 | // If scrollable, adjust
33 | if (isScrollable) {
34 | this._blockTouchMove = false;
35 | return this.scrollToEnd(el);
36 | }
37 | // Else block touchmove
38 | else {
39 | this._blockTouchMove = true;
40 | }
41 |
42 | },
43 | onTouchMove: function(e) {
44 | if (this._blockTouchMove) {
45 | e.preventDefault();
46 | }
47 | },
48 | onTouchEnd: function(e) {
49 | this._blockTouchMove = false;
50 | },
51 | render: function() {
52 | var props = assign({}, this.props, {
53 | onTouchStart: this.onTouchStart,
54 | onTouchMove: this.onTouchMove,
55 | onTouchEnd: this.onTouchEnd,
56 | onTouchCancel: this.onTouchEnd
57 | });
58 | delete props.componentClass;
59 |
60 | return React.createElement(this.props.componentClass, props, this.props.children);
61 | }
62 | });
63 |
64 | module.exports = Bouncefix;
65 |
--------------------------------------------------------------------------------