Skip to content
This repository was archived by the owner on May 7, 2022. It is now read-only.

Commit a57f33a

Browse files
committed
封装react-scroll组件
1 parent ca65416 commit a57f33a

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"babel-runtime": "^6.26.0",
6262
"fastclick": "^1.0.6",
6363
"history": "^4.6.1",
64+
"jroll": "^2.5.0",
6465
"prop-types": "^15.5.7-alpha.1",
6566
"react": "^15.6.1",
6667
"react-dom": "^15.6.1",

src/components/Commons/MyScroll.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Created by yongyuehuang on 2017/8/27.
3+
*/
4+
'use strict';
5+
/*
6+
* 如果你在移动端项目尝试过IScroll5,就会发现他的卡顿问题很难完美解决,于是我就在react中封装了下面这个性能更好的组件。
7+
* 该组件的作用和臭名昭著的IScroll插件相同,但是这个组件比IScroll封装的更好用,我已经在移动端项目全部页面使用了该组件。
8+
* 组件使用教程可以查看我写的一篇博客:https://segmentfault.com/a/1190000010042474
9+
* */
10+
exports.__esModule = true;
11+
12+
var _react = require('react');
13+
14+
var _react2 = _interopRequireDefault(_react);
15+
16+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17+
18+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19+
20+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
21+
22+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
23+
24+
var JRoll = require('jroll');
25+
26+
var MyJRoll = function (_React$Component) {
27+
_inherits(MyJRoll, _React$Component);
28+
29+
function MyJRoll(props) {
30+
_classCallCheck(this, MyJRoll);
31+
32+
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
33+
34+
_this.jroll = null;
35+
return _this;
36+
}
37+
38+
MyJRoll.prototype.componentDidMount = function componentDidMount() {
39+
var wrappers = this.props.ID || 'wrappers';
40+
this.jroll = new JRoll('#' + wrappers);
41+
this.jroll.refresh();
42+
};
43+
44+
MyJRoll.prototype.componentDidUpdate = function componentDidUpdate() {
45+
var _this2 = this;
46+
47+
setTimeout(function () {
48+
return _this2.jroll.refresh();
49+
}, 400);
50+
};
51+
52+
MyJRoll.prototype.render = function render() {
53+
var _props = this.props,
54+
height = _props.height,
55+
maxHeight = _props.maxHeight;
56+
57+
var _style = void 0;
58+
if (!maxHeight) {
59+
_style = { height: height ? height : "100%" };
60+
} else {
61+
_style = { maxHeight: maxHeight };
62+
}
63+
return _react2.default.createElement(
64+
'div',
65+
{ id: this.props.ID ? this.props.ID : 'wrappers', style: _style },
66+
_react2.default.createElement(
67+
'ul',
68+
{ id: 'scroller', className: 'clearfix' },
69+
this.props.children
70+
)
71+
);
72+
};
73+
74+
return MyJRoll;
75+
}(_react2.default.Component);
76+
77+
exports.default = MyJRoll;

0 commit comments

Comments
 (0)