简体   繁体   English

jQuery Mobile和iScroll问题

[英]jQuery Mobile and iScroll Problem

So I had found a good solution to solve the fixed header and footer problem in jquery mobile which is the iscoll library. 因此,我找到了一个很好的解决方案,用于解决jcoll mobile(即iscoll库)中固定的页眉和页脚问题。 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 为了使iscroll库与jquery mobile一起使用,我使用了以下第三方脚本: https : //github.com/yappo/javascript-jquery.mobile.iscroll

Everything works just fine for my listing pages (using jquery mobile list view). 一切对于我的列表页面都很好(使用jquery移动列表视图)。 My listing pages are loaded dynamically using ajax. 我的列表页面是使用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. 正如您在yappo包装器脚本中看到的那样,iscroll在pagebeforeshow事件上触发。 Here is the template of my product detail page. 这是我的产品详细信息页面的模板。 The content will be dynamically loaded and appended to the scroller div. 内容将被动态加载并附加到滚动条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? 这里的任何人都知道我错过了什么,或者你们当中有人设法使iscroll与jQuery Mobile完美配合?

I'm using jQuery Mobile beta 3 and iScroll 3.7.1. 我正在使用jQuery Mobile beta 3和iScroll 3.7.1。

Cheers 干杯

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: 过去,在使用iScroll和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. 如果可滚动区域内的内容具有CSS规则“ float”,则iScroll将无法确定内容的高度。 iScroll will think that there is nothing to scroll. iScroll会认为没有可滚动的内容。 So you may need to check the CSS rules applied to the scrollable content. 因此,您可能需要检查适用于可滚动内容的CSS规则。
  • jQuery Mobile automatically binds touch event to some elements. jQuery Mobile自动将触摸事件绑定到某些元素。 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() ). 当将iScroll与jQuery Mobile结合使用时,将一个单独的函数绑定到'touchmove'事件并防止该事件冒泡(event.preventDefault())是一个好主意。 By doing this jQuery Mobile will not be able to handle the touch event while users are interacting with the iScroll element. 这样,当用户与iScroll元素进行交互时,jQuery Mobile将无法处理触摸事件。

This are generic recommendation, but I hope they can help you. 这是一般性建议,但希望它们能为您提供帮助。 I wrote a little jQuery extension to integrate jQuery with iScroll. 我写了一个jQuery扩展,将jQuery与iScroll集成在一起。 You can get it at: 您可以在以下位置获得它:

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

In HTML5 based application, smooth scrolling is always challenging. 在基于HTML5的应用程序中,平滑滚动始终是挑战。 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. 在此滚动器库中,用户只需要在可滚动分区中添加scrollable = true属性,则该div就会像平滑的本机滚动器一样滚动。 Please read readme.doc file first to start working on it 请先阅读readme.doc文件以开始使用它

library link 图书馆链接

http://github.com/ashvin777/html5 http://github.com/ashvin777/html5

Advantages : 1 No need the manually create scroller object. 优点:1不需要手动创建滚动对象。 2 Scroller will automatically refreshed in case of any data being changed in the scroller. 2如果滚动条中的任何数据被更改,滚动条将自动刷新。 3 So no need to refresh manually. 3因此,无需手动刷新。 4 Nested Scrolling content also possible with no dual scrolling issue. 4嵌套滚动内容也可以,没有双重滚动问题。 5 Works for all webkit engines. 5适用于所有Webkit引擎。 6 In case if user wants to access that scroller object then he can access it by writing “SElement.scrollable_wrapper”. 6如果用户要访问该滚动对象,则可以通过编写“ SElement.scrollable_wrapper”来访问它。 scrollable_wrapper is id of the scrollable division which is defined in the html page. scrollable_wrapper是html页面中定义的可滚动分区的ID。

I dig deeper into the iScroll documentation and I found out that I need to refresh the iscroll object everytime the DOM changed. 我深入研究了iScroll文档,发现每次DOM更改时都需要刷新iscroll对象。 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. 我应该只学习Objective-C ...试图至少使用HTML来构建应用程序非常麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM