我正在开发一个滑动页面功能,我使用锤子的swiperight和swipeleft事件在部分工作之间滑动。但是在触摸设备(ipad)上,当你滑动时,它也会水平滚动,这非常烦人。因此,当我使用jquery .animate()时,动画有时会不顺畅,但它会直接跳转到next / prev页面而不是动画。我的代码在
之下有没有办法在滑动时停止ipad水平滚动?我知道eventDefault()可以,但它对我不起作用
Hammer(array[i]).on("swipeleft", function(e) {
//e.preventDefault(); -- this doesnt work :(
if(!$(this).next().length){
console.log("no more pages to right");
}
else{
$(this).next().animate({
marginLeft:"auto"
},{duration:500,queue:false});
$(this).animate({
marginLeft:"-" + windowWidth + "px"
},{duration:300,queue:false});
}
});
Hammer(array[i]).on("swiperight", function() {
if(!$(this).prev().length){
console.log("no more pages to left");
}
else{
$($(this)).animate({
marginLeft:windowWidth+"px"
},{duration:300,queue:false});
$($(this).prev()).animate({
marginLeft:"0px"
},{duration:400,queue: false});
}
});
答案 0 :(得分:1)
在研究了文档(https://github.com/EightMedia/hammer.js/wiki/Tips-&-Tricks)后,我发现了e.gesture.preventDefault()。所以我将它应用于该部分所在的容器。
$("#container").on("dragright dragleft",function(e){
e.gesture.preventDefault();
});