Skip to content

Commit 99187b5

Browse files
李钿李钿
authored andcommitted
横向列表第一张图片再往右滑动和最后一张图片再往左滑动,拖动距离增加阻塞算法
1 parent a23160e commit 99187b5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/components/ListContainer.jsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ class ListContainer extends PureComponent {
116116
isNeedSpring: false
117117
})
118118
}
119+
/**
120+
* 拖拽的缓动公式 - easeOutSine
121+
* Link http://easings.net/zh-cn#
122+
* t: current time(当前时间);
123+
* b: beginning value(初始值);
124+
* c: change in value(变化量);
125+
* d: duration(持续时间)。
126+
*/
127+
easing = (distance) => {
128+
var t = distance;
129+
var b = 0;
130+
var d = this.props.screenWidth; // 允许拖拽的最大距离
131+
var c = d / 2.5; // 提示标签最大有效拖拽距离
132+
133+
return c * Math.sin(t / d * (Math.PI / 2)) + b;
134+
}
119135

120136
handleStart = () =>{
121137
console.info("ListContainer handleStart")
@@ -127,7 +143,11 @@ class ListContainer extends PureComponent {
127143

128144
handleMove = (diffX) =>{
129145
console.info("ListContainer handleStart diffX = %s",diffX);
130-
146+
if(this.state.left >= 0 && diffX > 0){
147+
diffX = this.easing(diffX);
148+
} else if(this.state.left <= - this.maxLeft && diffX < 0){
149+
diffX = -this.easing(-diffX);
150+
}
131151
this.setState({
132152
left: this.startLeft + diffX,
133153
isNeedSpring: false

0 commit comments

Comments
 (0)