【发布时间】:2014-02-26 21:38:36
【问题描述】:
我正在开发一个滑动页面功能,我使用锤子的 swiperight 和 swipeleft 事件在有效的部分之间滑动。但是在触摸设备(ipad)上,当你滑动时,它也会水平滚动,这很烦人。因此,当我使用 jquery .animate() 时,动画有时并不流畅,即它直接跳转到下一页/上一页而不是动画。我的代码在下面
有没有办法在滑动时停止 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});
}
});
【问题讨论】:
标签: javascript jquery ipad hammer.js