简体   繁体   English

使用 iScroll 在 iOS 中的 web 应用程序中滚动

[英]Scrolling in web application in iOS with iScroll

I have a few web applications that were previously developed for use in Android apps, and we're trying to port them to iOS.我有一些 web 应用程序以前开发用于 Android 应用程序,我们正在尝试将它们移植到 iOS。

The first problem was that the ad we had was not staying in place, since position:fixed is no good in mobile Safari.第一个问题是我们的广告没有留在原地,因为 position:fixed 在移动端 Safari 中不好用。 So, I downloaded iScroll.所以,我下载了 iScroll。

I figured out that iScroll doesn't play nice with our RSS feed reader (zRSSFeed for jQuery).我发现 iScroll 不能与我们的 RSS 提要阅读器(jQuery 的 zRSSFeed)配合使用。 In fact, when both are enabled on the same page, the iScroll functionality "works", but gets stuck at the top of the page.事实上,当两者都在同一页面上启用时,iScroll 功能“工作”,但卡在页面顶部。

I posted to the iScroll user group (https://groups.google.com/group/iscroll/browse_thread/thread/5dd274ff4159a672) but got no useful answers.我发布到 iScroll 用户组 (https://groups.google.com/group/iscroll/browse_thread/thread/5dd274ff4159a672) 但没有得到有用的答案。

I even tried to change to a different RSS library, but it seems they all elicit this issue.我什至尝试更改为不同的 RSS 库,但似乎它们都引发了这个问题。

Has anyone had this issue before?以前有人遇到过这个问题吗? Has anyone solved it?有人解决了吗? Should I just give up and put the ad at the bottom of the webapp, or what?我应该放弃并将广告放在网络应用程序的底部,还是什么?

Thanks, all.谢谢大家。

EDIT: I figured I should add in a bit of code.编辑:我想我应该添加一些代码。

Basic structure of web stuff: web东西的基本结构:

....
<div id="appBody">
    <div id="feedResults">
        <!-- rss entries go here -->
    </div>
</div>
<div id="appAdvertisements">
    <!-- admob JS stuff goes here -->
</div>
....

Basic JS:基本JS:

var scroll;
document.addEventListener('touchmove', function (e) { e.preventDefault();}, false);
function loaded() {
    scroll = new iScroll('appBody');
    $('#feedResults').rssfeed('<feedurl>', {<options>}, function() { scroll.refresh() });
}
document.addEventListener('DOMContentLoaded', loaded, false);

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 无需手动创建滚动条 object。
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 如果用户想要访问该滚动条 object,那么他可以通过编写“SElement.scrollable_wrapper”来访问它。 scrollable_wrapper is id of the scrollable division which is defined in the html page. scrollable_wrapper 是在 html 页面中定义的可滚动分区的 id。

I would suggest you first populate the #feedResults with your parsed rss and oncomplete of this action, you start the iScroll.我建议您首先使用解析的 rss 填充#feedResults,并在完成此操作后启动 iScroll。 Don't start both at same time nor use refresh() without setTimeout like Matteo said in iScroll4 documentation.不要同时启动两者,也不要像 Matteo 在 iScroll4 文档中所说的那样在没有 setTimeout 的情况下使用 refresh() 。

Considering the function() after stands for the onComplete, try something like this:考虑到代表 onComplete 之后的 function(),请尝试以下操作:

var scroll;
function loaded() {
    $('#feedResults').rssfeed('<feedurl>', {<options>}, function() { 
        scroll = new iScroll('appBody');
    });
}
document.addEventListener('touchmove', function (e) { e.preventDefault();}, false);
document.addEventListener('DOMContentLoaded', loaded, false);

I think that will give time to the DOM to have your rss on it and then iscroll will calculate the correct height of your entire wrapper (appBody in this case).我认为这会给 DOM 时间让你的 rss 放在上面,然后 iscroll 将计算整个包装器的正确高度(在这种情况下为 appBody)。

I just had the exact same problem.我只是遇到了完全相同的问题。 The solution for me was to add position: absolute;我的解决方案是添加 position: absolute; to the element directly inside your wrapper, in your case you would need to add position: absolute;到包装器内的元素,在您的情况下,您需要添加 position: absolute; to feedResults.喂结果。

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

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