使用Jquery Mobile滑动页面 [英] Swipe pages using Jquery mobile

查看:102
本文介绍了使用Jquery Mobile滑动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人建议如何使用向左/向右移动查询来滑动页面

please any one suggest how to Swipe Pages using query mobile left/right

var nextpage = $(this).next('div[data-role="page"]');

不返回首页

推荐答案

工作示例: http://jsfiddle.净/JB22E/4/

<!DOCTYPE html>
<html>
    <head>
        <title>Share QR</title>
        <meta name="viewport" content="width=device-width,height=device-height,minimum-scale=1,maximum-scale=1"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />   
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    </head>

    <body>
        <div data-role="page" id="article1">
            <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
                <h1>Articles</h1>
            </div>
            <div data-role="content">
                <p>Article 1</p>
                <a data-role="button" id="add-dynamic-page">Add new dynamic page</a>
            </div>
            <div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
                <h1>Footer</h1>    
            </div>
        </div>

        <div data-role="page" id="article2">
            <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
                <a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
                <h1>Articles</h1>
            </div>
            <div data-role="content">
                <p>Article 2</p>
            </div>
            <div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
                <h1>Footer</h1>
            </div>
        </div>

        <div data-role="page" id="article3">
            <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
                <a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
                <h1>Articles</h1>
            </div>
            <div data-role="content">
                <p>Article 3</p>
            </div>
            <div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
                <h1>Footer</h1>
            </div>
        </div>        
    </body>
</html>

JavaScript:

$(document).on('pageinit', '#article1', function(){       
    $(document).on('click', '#add-dynamic-page', function(event){  
        if(event.handled !== true) // This will prevent event triggering more then once
        {          
            var nextPageId = parseInt($('body [data-role="page"]').length)+1;
            $('[data-role="page"]').last().after('<div data-role="page" id="article'+nextPageId+'"><div data-role="header" data-theme="b" data-position="fixed" data-id="footer"><h1>Articles</h1></div><div data-role="content"><p>Article '+nextPageId+'</p></div><div data-role="footer" data-theme="b" data-position="fixed" data-id="footer"><h1>Footer</h1></div></div>');
        }
    });       
});

$(document).off('swipeleft').on('swipeleft', '[data-role="page"]', function(event){    
    if(event.handled !== true) // This will prevent event triggering more then once
    {    
        var nextpage = $.mobile.activePage.next('[data-role="page"]');
        // swipe using id of next page if exists
        if (nextpage.length > 0) {
            $.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
        }
        event.handled = true;
    }
    return false;         
});

$(document).off('swiperight').on('swiperight', '[data-role="page"]', function(event){   
    if(event.handled !== true) // This will prevent event triggering more then once
    {      
        var prevpage = $(this).prev('[data-role="page"]');
        if (prevpage.length > 0) {
            $.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
        }
        event.handled = true;
    }
    return false;            
});

这是我几个月前创建的一个示例.您会找到所需的一切,还有更多.只需滑动即可查看一切工作原理,甚至可以单击添加新动态页面"以查看此示例如何处理动态添加的页面.

This is an example I created few months ago. You will find everything you need + more. Just swipe to see how everything works, you can even click "Add new dynamic page" to see how this example handles dynamically added pages.

这篇关于使用Jquery Mobile滑动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆