Skip to content

Commit 52ea2b7

Browse files
李钿李钿
authored andcommitted
增加 getScrollTop setScrollTop
1 parent 13b2a21 commit 52ea2b7

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

demo/App.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ export class App extends Component{
7777
action: action
7878
})
7979
}
80+
81+
getScrollTop = ()=>{
82+
if(this.refs.reactpullload){
83+
console.info(this.refs.reactpullload.getScrollTop());
84+
}
85+
}
86+
setScrollTop = ()=>{
87+
if(this.refs.reactpullload){
88+
console.info(this.refs.reactpullload.setScrollTop(100));
89+
}
90+
}
8091

8192
render(){
8293
const {
@@ -97,13 +108,22 @@ export class App extends Component{
97108
zIndex: 1
98109
}
99110

111+
const fixButtonStyle = {
112+
position: "fixed",
113+
top: 200,
114+
width: "100%",
115+
}
116+
100117
return (
101118
<div>
102119
<div style={fixHeaderStyle}>
103120
fixed header
104121
</div>
105122
<ReactPullLoad
106123
downEnough={150}
124+
ref="reactpullload"
125+
className="block"
126+
isBlockContainer={true}
107127
action={this.state.action}
108128
handleAction={this.handleAction}
109129
hasMore={hasMore}
@@ -112,6 +132,10 @@ export class App extends Component{
112132
<ul className="test-ul">
113133
<button onClick={this.handleAction.bind(this, STATS.refreshing)}>refreshing</button>
114134
<button onClick={this.handleAction.bind(this, STATS.loading)}>loading more</button>
135+
<div style={fixButtonStyle}>
136+
<button onClick={this.getScrollTop}>getScrollTop</button>
137+
<button onClick={this.setScrollTop}>setScrollTop</button>
138+
</div>
115139
{
116140
data.map( (str, index )=>{
117141
return <li key={index}><img src={str} alt=""/></li>

lib/ReactPullLoad.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ var ReactPullLoad = function (_Component) {
6868

6969
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ReactPullLoad.__proto__ || Object.getPrototypeOf(ReactPullLoad)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
7070
pullHeight: 0
71+
}, _this.getScrollTop = function () {
72+
if (_this.defaultConfig.container) {
73+
return _this.defaultConfig.container.scrollTop;
74+
} else {
75+
return 0;
76+
}
77+
}, _this.setScrollTop = function (value) {
78+
if (_this.defaultConfig.container) {
79+
var conH = _this.defaultConfig.container === document.body ? document.documentElement.clientHeight : _this.defaultConfig.container.offsetHeight;
80+
if (value < 0) {
81+
value = 0;
82+
}
83+
if (value > conH) {
84+
value = conH;
85+
}
86+
return _this.defaultConfig.container.scrollTop = value;
87+
} else {
88+
return 0;
89+
}
7190
}, _this.easing = function (distance) {
7291
// t: current time, b: begInnIng value, c: change In value, d: duration
7392
var t = distance;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-pullload",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "React compopnent pull down refresh and pull up load more",
55
"main": "./lib/index.js",
66
"scripts": {

src/ReactPullLoad.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ export default class ReactPullLoad extends Component {
9595
}
9696
}
9797

98+
getScrollTop = ()=>{
99+
if(this.defaultConfig.container){
100+
return this.defaultConfig.container.scrollTop;
101+
} else{
102+
return 0;
103+
}
104+
}
105+
106+
setScrollTop = (value)=>{
107+
if(this.defaultConfig.container){
108+
let conH = this.defaultConfig.container === document.body ? document.documentElement.clientHeight : this.defaultConfig.container.offsetHeight
109+
if(value < 0){ value = 0}
110+
if(value > conH){ value = conH}
111+
return this.defaultConfig.container.scrollTop = value;
112+
} else{
113+
return 0;
114+
}
115+
}
116+
98117
// 拖拽的缓动公式 - easeOutSine
99118
easing = (distance) => {
100119
// t: current time, b: begInnIng value, c: change In value, d: duration

webpack.demo.dev.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var webpack = require('webpack');
22
var HtmlWebpackPlugin = require('html-webpack-plugin');
33
var path = require('path');
4-
var devport = 3002;
4+
var devport = 3003;
55

66
module.exports = {
77
context: path.resolve('demo'),
88
entry: [
99
'babel-polyfill',
10-
'./App2.jsx'
10+
'./App.jsx'
1111
],
1212
plugins: [
1313
new webpack.DefinePlugin({

0 commit comments

Comments
 (0)