jQuery Mobile 和 iScroll 问题

发布于 2024-12-06 16:15:50 字数 2408 浏览 1 评论 0原文

所以我找到了一个很好的解决方案来解决 jquery mobile 中的固定页眉和页脚问题,即 iscoll 库。为了让 iscroll 库与 jquery mobile 一起使用,我使用了这个第三方脚本: https://github.com/yappo/javascript-jquery.mobile.iscroll

对于我的列表页面(使用 jquery 移动列表视图),一切正常。我的列表页面是使用 ajax 动态加载的。但是,当我创建一个应该滚动的产品详细信息页面时,它根本不起作用。在某些情况下,我根本无法滚动。在某些其他情况下,滚动的行为就像橡皮筋效果,它总是让您再次回到顶部。但是,页眉和页脚导航栏已按照我想要的方式固定。

所以,这是场景。我有一个列表页面(带有滚动),当您单击任何列表项时,您应该在不同的页面上看到产品详细信息。 iscroll 在 pagebeforeshow 事件上触发,正如您在 yappo 包装脚本中看到的那样。这是我的产品详细信息页面的模板。内容将动态加载并附加到滚动条 div 中。

<!-- PROMOTION DETAIL PAGE -->
  <div data-role="page" id="page-promotion-detail" data-iscroll="enable"> 
      <div class="header" data-role="header">
          <div class="sub-header-bg">
              <div class="title"></div>
              <a href="#" id="Back" data-rel="back" class="btn-header-left btn-back"><span>Back</span></a>
              <a href="#" id="Edit" class="btn-header-right btn-edit hidden"><span>Edit</span></a>
          </div>
      </div>
      <div class="content" data-role="content" data-theme="anz">
          <div data-iscroll="scroller" class="scroller">
              <div data-iscroll="scroller"></div>
          </div>
          <input type="hidden" id="paramPromotionID" name="paramPromotionID" value="" />
      </div>
      <div class="footer" data-id="footer" data-role="footer">
          <div data-role="navbar">
              <ul>
                  <li><a id="menuHome" href="#page-home" class="footer-icon footer-icon-home">Home</a></li>
                  <li><a id="menuMySpot" href="#page-myspot" class="footer-icon footer-icon-spot">My Spot</a></li>
                  <li><a id="menuOtherCountries" href="#page-other-countries" class="footer-icon footer-icon-country">Others</a></li>
                  <li><a id="menuSearch" href="#page-search" class="footer-icon footer-icon-search">Search</a></li>
              </ul>
          </div>
      </div>
  </div>

这里有人知道我错过了什么,或者你们中有人设法让 iscroll 与 jQuery Mobile 完美配合吗?

我正在使用 jQuery Mobile beta 3 和 iScroll 3.7.1。

干杯

So I had found a good solution to solve the fixed header and footer problem in jquery mobile which is the iscoll library. To get the iscroll library to work with the jquery mobile, I'm using this third party script: https://github.com/yappo/javascript-jquery.mobile.iscroll

Everything works just fine for my listing pages (using jquery mobile list view). My listing pages are loaded dynamically using ajax. But then, when I created a product detail page that is supposed to scroll, it didn't work at all. In some cases, I couldn't scroll at all. In some other cases, the scrolling behaves like rubber band effect, it always brings you back to the top again. But, the header and footer navigation bars are fixed as what I want it to be.

So, here is the scenario. I have a listing page (with scrolling), when you click on any list item, you should see the product detail on a different page. The iscroll is triggered on pagebeforeshow event as you can see inside the yappo wrapper script. Here is the template of my product detail page. The content will be dynamically loaded and appended to the scroller div.

<!-- PROMOTION DETAIL PAGE -->
  <div data-role="page" id="page-promotion-detail" data-iscroll="enable"> 
      <div class="header" data-role="header">
          <div class="sub-header-bg">
              <div class="title"></div>
              <a href="#" id="Back" data-rel="back" class="btn-header-left btn-back"><span>Back</span></a>
              <a href="#" id="Edit" class="btn-header-right btn-edit hidden"><span>Edit</span></a>
          </div>
      </div>
      <div class="content" data-role="content" data-theme="anz">
          <div data-iscroll="scroller" class="scroller">
              <div data-iscroll="scroller"></div>
          </div>
          <input type="hidden" id="paramPromotionID" name="paramPromotionID" value="" />
      </div>
      <div class="footer" data-id="footer" data-role="footer">
          <div data-role="navbar">
              <ul>
                  <li><a id="menuHome" href="#page-home" class="footer-icon footer-icon-home">Home</a></li>
                  <li><a id="menuMySpot" href="#page-myspot" class="footer-icon footer-icon-spot">My Spot</a></li>
                  <li><a id="menuOtherCountries" href="#page-other-countries" class="footer-icon footer-icon-country">Others</a></li>
                  <li><a id="menuSearch" href="#page-search" class="footer-icon footer-icon-search">Search</a></li>
              </ul>
          </div>
      </div>
  </div>

Anyone here knows what i missed out or anyone of you guys managed to get iscroll to work perfectly with jQuery Mobile?

I'm using jQuery Mobile beta 3 and iScroll 3.7.1.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〗斷ホ乔殘χμё〖 2024-12-13 16:15:51

在基于 HTML5 的应用程序中,平滑滚动总是具有挑战性。有第三方库可用于实现平滑滚动器,但实现非常复杂。在这个滚动条库中,用户只需要在可滚动分区中添加scrollable=true属性,那么该div就会像平滑的原生滚动条一样滚动。请先阅读 readme.doc 文件以开始处理它

库链接

http://github.com/ashvin777/html5

优点:
1 无需手动创建滚动条对象。
2 如果滚动条中的任何数据发生更改,滚动条将自动刷新。
3 所以不需要手动刷新。
4 嵌套滚动内容也是可能的,没有双重滚动问题。
5 适用于所有 webkit 引擎。
6 如果用户想要访问该滚动条对象,则可以通过编写“SElement.scrollable_wrapper”来访问它。 scrollable_wrapper 是在 html 页面中定义的可滚动分区的 id。

In HTML5 based application, smooth scrolling is always challenging. There are third parties libraries available to implement smooth scroller but there implementation is very complex. In this scroller library, user only need to add scrollable=true attribute in the scrollable division, then that div will scroll like smooth native scroller. Please read readme.doc file first to start working on it

library link

http://github.com/ashvin777/html5

Advantages :
1 No need the manually create scroller object.
2 Scroller will automatically refreshed in case of any data being changed in the scroller.
3 So no need to refresh manually.
4 Nested Scrolling content also possible with no dual scrolling issue.
5 Works for all webkit engines.
6 In case if user wants to access that scroller object then he can access it by writing “SElement.scrollable_wrapper”. scrollable_wrapper is id of the scrollable division which is defined in the html page.

虚拟世界 2024-12-13 16:15:50

如果不查看实际应用程序,很难判断解决方案是什么。过去,我在使用 iScroll 和 jQuery Mobile 时注意到以下问题:

  • 如果可滚动区域内的内容具有 CSS 规则“float”,iScroll 将无法确定内容的高度。 iScroll会认为没有什么可以滚动的。因此,您可能需要检查应用于可滚动内容的 CSS 规则。
  • jQuery Mobile 自动将触摸事件绑定到某些元素。将 iScroll 与 jQuery Mobile 结合使用时,最好将一个单独的函数绑定到“touchmove”事件并防止该事件冒泡 ( event.preventDefault() )。通过这样做,当用户与 iScroll 元素交互时,jQuery Mobile 将无法处理触摸事件。

这是一般性的建议,但我希望它们可以帮助你。我编写了一个小的 jQuery 扩展来将 jQuery 与 iScroll 集成。您可以在以下位置获取它:

http://appcropolis.com/blog/jquery-wrapper- for-iscroll/

Without looking at the actual application is hard to tell what the solution might be. In the past I noticed the following issues when using iScroll and jQuery Mobile:

  • If the content inside the scrollable area has the CSS rule 'float' iScroll will not be able to determine the height of the content. iScroll will think that there is nothing to scroll. So you may need to check the CSS rules applied to the scrollable content.
  • jQuery Mobile automatically binds touch event to some elements. When combining iScroll with jQuery Mobile it might be a good idea to bind a separate function to the 'touchmove' event and prevent the event from bubbling up ( event.preventDefault() ). By doing this jQuery Mobile will not be able to handle the touch event while users are interacting with the iScroll element.

This are generic recommendation, but I hope they can help you. I wrote a little jQuery extension to integrate jQuery with iScroll. You can get it at:

http://appcropolis.com/blog/jquery-wrapper-for-iscroll/

对你而言 2024-12-13 16:15:50

我深入研究了 iScroll 文档,发现每次 DOM 更改时都需要刷新 iscroll 对象。这是必需的,因为它需要在更改后重新计算实际的高度/宽度。

我应该只学习 Objective-C...尝试使用 HTML 构建应用程序实在是太麻烦了...至少现在是这样。

I dig deeper into the iScroll documentation and I found out that I need to refresh the iscroll object everytime the DOM changed. This is required because it needs to recalculate the actual height / width after the changes.

I should've just learn Objective-C...trying to build apps using HTML is simply too much hassle..at least for now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文