This commit is contained in:
梁灏 2017-10-13 17:10:30 +08:00
parent 9d275e38f1
commit 59dbe5d565

View file

@ -22,6 +22,7 @@
<script> <script>
import throttle from 'lodash.throttle'; import throttle from 'lodash.throttle';
import loader from './loading-component.vue'; import loader from './loading-component.vue';
import { on, off } from '../../utils/dom';
const prefixCls = 'ivu-scroll'; const prefixCls = 'ivu-scroll';
const dragConfig = { const dragConfig = {
@ -159,7 +160,7 @@
// if we remove the handler too soon the screen will bump // if we remove the handler too soon the screen will bump
if (this.touchScroll) { if (this.touchScroll) {
setTimeout(() => { setTimeout(() => {
window.removeEventListener('touchend', this.pointerUpHandler); off(window, 'touchend', this.pointerUpHandler);
this.$refs.scrollContainer.removeEventListener('touchmove', this.pointerMoveHandler); this.$refs.scrollContainer.removeEventListener('touchmove', this.pointerMoveHandler);
this.touchScroll = false; this.touchScroll = false;
}, 500); }, 500);
@ -233,7 +234,7 @@
this.$refs.scrollContainer.scrollTop = 5; this.$refs.scrollContainer.scrollTop = 5;
this.pointerTouchDown = this.getTouchCoordinates(e); this.pointerTouchDown = this.getTouchCoordinates(e);
window.addEventListener('touchend', this.pointerUpHandler); on(window, 'touchend', this.pointerUpHandler);
this.$refs.scrollContainer.parentElement.addEventListener('touchmove', e => { this.$refs.scrollContainer.parentElement.addEventListener('touchmove', e => {
e.stopPropagation(); e.stopPropagation();
this.pointerMoveHandler(e); this.pointerMoveHandler(e);
@ -252,7 +253,6 @@
if (!this.touchScroll) { if (!this.touchScroll) {
const wasDragged = Math.abs(yDiff) > dragConfig.minimumStartDragOffset; const wasDragged = Math.abs(yDiff) > dragConfig.minimumStartDragOffset;
if (wasDragged) this.touchScroll = true; if (wasDragged) this.touchScroll = true;
else return;
} }
}, },
@ -260,7 +260,7 @@
this.pointerTouchDown = null; this.pointerTouchDown = null;
} }
}, },
created(){ created() {
this.handleScroll = throttle(this.onScroll, 150, {leading: false}); this.handleScroll = throttle(this.onScroll, 150, {leading: false});
this.pointerUpHandler = this.onPointerUp.bind(this); // because we need the same function to add and remove event handlers this.pointerUpHandler = this.onPointerUp.bind(this); // because we need the same function to add and remove event handlers
this.pointerMoveHandler = throttle(this.onPointerMove, 50, {leading: false}); this.pointerMoveHandler = throttle(this.onPointerMove, 50, {leading: false});