带滑动过渡的jQuery Mobile changePage

时间:2012-11-21 10:44:51

标签: jquery-mobile

在处理“swiperight”事件时,我似乎无法制作“反向”幻灯片效果。所以,下面的代码工作正常,但我希望当我制作“swiperight”时,下一页将从左侧而不是右侧滑入。我确实搜索了文档并将reverse: true as it recomends添加到了“swiperight”中:

$.mobile.changePage("#page"+nextPage, {transition : "slide", reverse:true});

但是这并没有提供想要的效果。你能指出我做错了吗?

我在jsFiddle上有以下代码:

HTML

<!DOCTYPE html>
<html>
<head>
    <title>jQuery Mobile Application</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>    
</head>

<body>
    <section id="page1" data-role="page">
        <header data-role="header"><h1>jQuery Mobile</h1></header>

        <div data-role="content" class="content">
            <p>First page!</p>
        </div>
        <footer data-role="footer"><h1>O'Reilly</h1></footer>
    </section>

    <section id="page2" data-role="page">
        <header data-role="header"><h1>jQuery Mobile</h1></header>

        <div data-role="content" class="content">
            <p>Second page!</p>
        </div>
        <footer data-role="footer"r><h1>O'Reilly</h1></footer>
    </section>

    <section id="page3" data-role="page">
        <header data-role="header"><h1>jQuery Mobile</h1></header>

        <div data-role="content" class="content">
            <p>Third page!</p>
        </div>
        <footer data-role="footer"><h1>O'Reilly</h1></footer>
    </section>    
</body>
</html>​

的jQuery

(function($) {
    var methods = {
        init : function(options) {
            var settings = {
                callback: function() {}
            };

            if ( options ) {
                $.extend( settings, options );
                }

            $(":jqmData(role='page')").each(function() {
                $(this).bind("swiperight", function() {
                    var nextPage = parseInt($(this).attr("id").split("page")[1]) - 1;
                    if (nextPage === 0) 
                        nextPage = 3;

                    $.mobile.changePage("#page"+nextPage, "slide");
                    });                        

                $(this).bind("swipeleft", function() {
                    var nextPage = parseInt($(this).attr("id").split("page")[1]) +1;
                    if (nextPage === 4) 
                        nextPage = 1;

                    $.mobile.changePage("#page"+nextPage, "slide");
                });
            })
        }
        }

    $.fn.initApp = function(method) {
        if ( methods[method] ) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } 
        else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } 
        else {
            $.error( 'Method ' + method + ' does not exist' );
        }
    }
    })(jQuery);

$(document).ready(function(){
    $().initApp();
});
​

1 个答案:

答案 0 :(得分:2)

首先,您可以使用Alpha版本的jQM以及您为jQM 1.1.1引用的文档。我已经更新了你的jsfiddle以使用最新的jQM 1.2

我已经为反向滑动过渡添加了正确的语法

$.mobile.changePage("#page"+nextPage, {
        transition: "slide",
        reverse: false
    });
});

和反向过渡

$.mobile.changePage("#page"+nextPage, {
        transition: "slide",
        reverse: true
    });
}); 
相关问题