diff --git a/dist/index/index.js b/dist/index/index.js index c556f19..69a7ce8 100644 --- a/dist/index/index.js +++ b/dist/index/index.js @@ -99,26 +99,16 @@ Component({ triggerCallback(options){ this.triggerEvent('change',options) }, - handlerFixedTap(event){ - const eindex = event.currentTarget.dataset.index; - const item = this.getCurrentItem(eindex); - this.setData({ - scrollTop : item.top, - currentName : item.currentName, - isTouches : true - }) - this.triggerCallback({ - index : eindex, - current : item.currentName - }) - }, handlerTouchMove(event){ const data = this.data; const touches = event.touches[0] || {}; const pageY = touches.pageY; const rest = pageY - data.startTop; - let index = Math.ceil( rest/data.itemHeight ); + let index = Math.floor( rest/data.itemHeight ); index = index >= data.itemLength ? data.itemLength -1 : index; + if(index<0){ + return ; + } const movePosition = this.getCurrentItem(index); /* @@ -155,4 +145,4 @@ Component({ }).exec() } } -}) \ No newline at end of file +}) diff --git a/dist/index/index.wxml b/dist/index/index.wxml index f83d847..020b4c9 100644 --- a/dist/index/index.wxml +++ b/dist/index/index.wxml @@ -13,7 +13,7 @@ wx:for="{{fixedData}}" wx:key="{{index}}" data-index="{{index}}" - catchtap="handlerFixedTap"> + > {{item}} diff --git a/src/index/index.js b/src/index/index.js index c556f19..69a7ce8 100644 --- a/src/index/index.js +++ b/src/index/index.js @@ -99,26 +99,16 @@ Component({ triggerCallback(options){ this.triggerEvent('change',options) }, - handlerFixedTap(event){ - const eindex = event.currentTarget.dataset.index; - const item = this.getCurrentItem(eindex); - this.setData({ - scrollTop : item.top, - currentName : item.currentName, - isTouches : true - }) - this.triggerCallback({ - index : eindex, - current : item.currentName - }) - }, handlerTouchMove(event){ const data = this.data; const touches = event.touches[0] || {}; const pageY = touches.pageY; const rest = pageY - data.startTop; - let index = Math.ceil( rest/data.itemHeight ); + let index = Math.floor( rest/data.itemHeight ); index = index >= data.itemLength ? data.itemLength -1 : index; + if(index<0){ + return ; + } const movePosition = this.getCurrentItem(index); /* @@ -155,4 +145,4 @@ Component({ }).exec() } } -}) \ No newline at end of file +}) diff --git a/src/index/index.wxml b/src/index/index.wxml index f83d847..020b4c9 100644 --- a/src/index/index.wxml +++ b/src/index/index.wxml @@ -13,7 +13,7 @@ wx:for="{{fixedData}}" wx:key="{{index}}" data-index="{{index}}" - catchtap="handlerFixedTap"> + > {{item}}