Skip to content

Commit

Permalink
添加滑动时阻止页面滚动 #2
Browse files Browse the repository at this point in the history
添加滑动时阻止页面滚动
  • Loading branch information
warpcgd committed Oct 31, 2016
1 parent 3b4bf7a commit 4d4107e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions components/slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,15 @@ export default {
},
methods:{
swipeStart (e) {
let that = this ;
this.basicdata.animation['animation-ease'] = false;
// 暂停自动滚动
if(this.sliderinit.autoplay){
let that = this;
this.clock().stop(that);
}
// 阻止页面滚动
document.addEventListener('touchmove',that.preventDefault(e));
if (e.type === 'touchstart') {
if (e.touches.length>1) {
this.sliderinit.tracking = false;
Expand Down Expand Up @@ -316,14 +319,14 @@ export default {
this.sliderinit.end.y = e.clientY;
}
if(this.sliderinit.direction == 'vertical'){
console.log('yes');
this.basicdata.posheight = -(this.currentHeight) + this.sliderinit.end.y - this.sliderinit.start.y + 'px';
return
}
this.basicdata.poswidth = -(this.currentWidth) + this.sliderinit.end.x - this.sliderinit.start.x + 'px';
}
},
swipeEnd (e) {
let that = this;
this.sliderinit.tracking = false;
let now = new Date().getTime();
let deltaTime = now - this.sliderinit.start.t;
Expand All @@ -333,9 +336,11 @@ export default {
if(this.sliderinit.autoplay){
let that = this;
setTimeout(function(){
that.clock().begin(that);
that.clock().begin(that);
},350);
}
};
// 解除阻止
document.removeEventListener('touchmove',that.preventDefault(e));
/* work out what the movement was */
if (deltaTime > this.sliderinit.thresholdTime) {
this.slide(this.sliderinit.currentPage);
Expand Down Expand Up @@ -440,10 +445,14 @@ export default {
}
},
stop:function(that){
clearInterval(that.setIntervalid);
clearInterval(that.setIntervalid)
},
}
},
// 阻止页面滚动
preventDefault(e){
e.preventDefault(e);
}
}
}
Expand Down

0 comments on commit 4d4107e

Please sign in to comment.