0

我有 ipad web 应用程序,我正在滚动特定的 div,它工作正常,但问题是当用户在 div 旁边伸出时,页面也滚动我想停止页面滚动并使 div 只滚动。

I used


 document.ontouchmove=function(e) { e.preventDefault()};

但它也会在 div 上停止滚动整个页面。

这是我正在处理的索引文件链接

http://codepad.org/7RE5vx74

4

1 回答 1

1

给 div 一个类(比如,'scrollThis')。处理 touchmove 事件的方式是,如果 touchmove 事件的目标不是 div,则防止滚动。否则,让它发生。

$('body').on('touchmove', function (e) {
    if (!$('.scrollThis').has($(e.target)).length) //check if the div isn't being scrolled
      e.preventDefault();
});

我已经在 iOS/android 网络应用程序中使用了它,所以我可以保证它可以工作。

于 2013-06-04T09:46:06.557 回答