简体   繁体   English

jQuery mobile + iScroll,无法向下滚动

[英]jQuery mobile + iScroll, cannot scroll down

I'm trying to integrate jQuery Mobile with iScroll 4 . 我正在尝试将jQuery MobileiScroll 4集成。 I am aware that there is already a project that does this, however, I'm avoiding it due to a bug with input-elements (page jumping like crazy when typing). 我知道已经有一个项目可以做到这一点,但是,由于输入元素的错误 (在打字时页面跳得像疯了),我正在避免它。

My current implementation looks like this: 我目前的实现如下:

http://jsfiddle.net/AqHsW/ - (JSFiddle example) [ Alternative mirror ] http://jsfiddle.net/AqHsW/ - (JSFiddle示例) [ 替代镜像 ]

As you probably noted, this works flawlessly, except for one major catch: one cannot scroll down. 正如你可能已经注意到的那样,除了一个主要问题之外,这个工作完美无瑕: 一个人无法向下滚动。 This problem seems to be cross-os / browser. 这个问题似乎是跨操作系统/浏览器。

However, if my I override the onBeforeScrollStart method: 但是,如果我覆盖onBeforeScrollStart方法:

var scroller = new iScroll('wrapper', { onBeforeScrollStart: null });

It works somewhat better. 它的效果要好一些。 Now one can scroll, but the behaviour gets glitchy (along with slow responsiveness) instead, allowing the user to scroll how high he wants and so on. 现在可以滚动,但行为变得有毛病(同时响应速度慢),允许用户滚动他想要的高度等等。

(Doing this only seems to alter things on iOS, however) (这样做似乎只会改变iOS上的内容)

I'm now looking for a solution to this problem, which preferably supports iOS 5 and 6, along with the use of <input> elements. 我现在正在寻找这个问题的解决方案,它最好支持iOS 5和6,以及<input>元素的使用。 This should be a pretty common problem, considering that iScroll and jQuery Mobile are the two dominating frameworks today. 考虑到iScroll和jQuery Mobile是当今两个主导框架,这应该是一个非常普遍的问题。

I played a bit with your code, found a couple of things and a solution, check the jsfiddle . 我玩了一些你的代码,找到了一些东西和解决方案,检查jsfiddle

  • Since your loading jQuery , make use of jQuery(document).ready() . 由于你加载jQuery ,使用jQuery(document).ready()

  • It seemed more appropriate to init iScroll on the wrapper 's direct child element rather than the wrapper . wrapper的直接子元素而不是wrapper上初始化iScroll似乎更合适。

  • Instead of setting the wrapper height via CSS, I used javascript to be more precise and avoid overflows. 我没有通过CSS设置包装器高度,而是使用javascript更精确并避免溢出。

  • FYI, scroll was already defined as a function. 仅供参考, scroll已被定义为函数。 (in your fiddle you used scroll as a variable) (在您的小提琴中,您使用scroll作为变量)

  • Now it works like a charm! 现在它就像一个魅力!


$(function(){

    var footerHeight = $('[data-role="footer"]').outerHeight(true),
        headerHeight = $('[data-role="header"]').outerHeight(true),
        padding = 15*2; //ui-content padding

   $('#wrapper, #scroller').height( $(window).innerHeight() - headerHeight - footerHeight - padding );

   // To make inputs focusable,
   // you can rebind their touchend's event to trigger their focus

   $('input').on('touchend', function(){
       $(this).focus();
   });

   var iScroller = new iScroll('scroller');

});​

你可能会看到这个演示: http//lab.cubiq.org/iscroll5/demos/event-passthrough/

myScroll = new IScroll('#wrapper', { eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false });

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

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