【问题标题】:Scroll the content of a certain div in a jQuery-mobile 'page' and not the page itself滚动 jQuery 移动“页面”中某个 div 的内容,而不是页面本身
【发布时间】:2013-12-26 18:01:01
【问题描述】:

我正在将 jQuery-mobile 用于基于 html 的移动应用程序。

我使用 jQuery-mobile 通过滑动来水平滚动页面。

我的一个页面有一个水平长的 div,其中包含一些动画内容。我只需要将这个 div 的内容滚动到一边。但是当我在 div 上滑动时,jQuery-mobile 会滚动到下一页。

如果用户在页面的任何其他部分上滑动,这是所需的行为,但是当在该特定 div 上发生滑动时,我只需要滚动内容。

我尝试按照 here 的建议使用 iScrollView 并按照 here 的建议使用 css 溢出,但在每种情况下,jQuery-mobile 都会滚动页面。

有没有办法只滚动 jQuery 移动“页面”中某个 div 的内容而不是页面本身?

【问题讨论】:

  • 你在使用swipeleft / swiperight吗?如果e.target 等于那个div,你可以e.preventDefault()
  • 谢谢@Omar。我试过了,它阻止了页面滚动。但 div 也不滚动。
  • 好的。我想通过将 overflow: scroll; 添加到容器中来滚动 div。
  • 很高兴你解决了 :)
  • @Omar,您为什么不将您的评论作为答案,以便我接受?

标签: css jquery-mobile


【解决方案1】:

您可以preventDefault()return false 滑动特定元素及其子元素。

使用.class 标识该元素。

$(document).on("swipeleft swiperight", function (e) {
  if ($(e.target).hasClass("class") || $(".class").has(e.target).length) {
    /* true */
    return false;
  } 
  else {
    /* false */
    doSomething();
  }
});

Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多