File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ class ImageContainer extends PureComponent {
4747 maxZoomNum : 4 ,
4848 }
4949
50+ static contextTypes = {
51+ onClose : PropTypes . func
52+ } ;
53+
5054 state = {
5155 width : 0 ,
5256 height : 0 ,
@@ -80,6 +84,8 @@ class ImageContainer extends PureComponent {
8084 if ( this . state . width === this . originWidth ) {
8185 this . callHandleStart ( )
8286 }
87+ this . onTouchStartTime = ( new Date ( ) ) . getTime ( ) ;
88+ this . isTap = true ;
8389 break ;
8490
8591 case 2 : //两个手指
@@ -118,6 +124,11 @@ class ImageContainer extends PureComponent {
118124 let targetEvent = event . touches [ 0 ] ,
119125 diffX = targetEvent . clientX - this . startX ,
120126 diffY = targetEvent . clientY - this . startY ;
127+
128+ //判断是否移动
129+ if ( Math . abs ( diffX ) > 5 || Math . abs ( diffY ) > 5 ) {
130+ this . isTap = false ;
131+ }
121132
122133 //图片宽度等于初始宽度,直接调用 handleMove 函数
123134 if ( this . state . width === this . originWidth ) {
@@ -228,6 +239,10 @@ class ImageContainer extends PureComponent {
228239 }
229240 } else { //单指结束(ontouchend)
230241 this . callHandleEnd ( ) ;
242+ let diffTime = ( new Date ( ) ) . getTime ( ) - this . onTouchStartTime
243+ if ( diffTime < 100 && this . isTap ) {
244+ this . context . onClose ( ) ;
245+ }
231246 }
232247 event . preventDefault ( ) ;
233248 }
You can’t perform that action at this time.
0 commit comments