Laggy轻扫性能

时间:2012-12-21 15:12:53

标签: android cordova jquery-mobile knockout.js

我有一个jQuery Mobile应用程序,我正试图通过Phonegap在Galaxy Tab设备上运行。一切都按预期工作,但我有一个滑动用于在一组页面之间转换,这是非常滞后。

我实际上正在使用knockoutJS和这样的自定义绑定:

<!-- ko foreach: factors -->
<div data-role="page" data-bind="attr: { id: id }, swipe: $data"> 
    <!-- some content here that I don't *think* is the problem -->
</div>
<!-- /ko -->

ko.bindingHandlers["swipe"] = {
    init: function (element, valueAccessor) {
        var qe = $(element);
        var val = ko.utils.unwrapObservable(valueAccessor());
        qe.bind("swipeleft", function () {
            var next = qe.next("div[data-role='page'][data-bind*='swipe']");
            if(next.length) {
                $.mobile.changePage(next, {
                    transition: "slide"
                });
            } else {
                qe.effect("shake");
            }
        });
        qe.bind("swiperight", function () {
            var prev = qe.prev("div[data-role='page']");
            if(prev.length) {
                $.mobile.changePage(prev, {
                    transition: "slide",
                    reverse: true
                });
            } else {
                qe.effect("shake");
            }
        });
    }

我尝试从网页上删除了几乎所有内容,但没有帮助。我尝试用slide替换none过渡,这有点帮助,但性能仍然慢得令人无法接受。

使这项工作合理的任何技巧或提示?

1 个答案:

答案 0 :(得分:2)

这至少给了我部分解决方案:

Swipe with jQuery Mobile 1.2, PhoneGap 2.1 and Android 4.0.4 not working properly

似乎绑定vmousemouse并将其设置为preventDefault会使滑动效果更好,但同时会禁用滚动!