函数与Jquery 1.6.4一起使用,不适用于Jquery 1.9.1

时间:2013-04-30 14:11:02

标签: jquery cordova jquery-mobile

我正在使用JQM框架进行phonegap项目。

在这个项目中,我正在尝试左侧滑动(打开)和向右滑动(关闭)的导航菜单。

代码在Jquery 1.6.4上运行良好。

但是当我将Jquery 1.9.1导入我的项目时,它不起作用。按钮单击有效,但滑动不行。

不要告诉我继续1.6.4然后请,我需要帮助:))

这是我的功能;

    $(function(){
    var menuStatus;

    $("a.showMenu").click(function(){
        if(menuStatus != true){             
        $(".ui-page-active").animate({
            marginLeft: "265px",
          }, 300, function(){menuStatus = true});
          return false;
          } else {
            $(".ui-page-active").animate({
            marginLeft: "0px",
          }, 300, function(){menuStatus = false});
            return false;
          }
    });

    $('.pages').live("swipeleft", function(){
        if (menuStatus){    
        $(".ui-page-active").animate({
            marginLeft: "0px",
          }, 300, function(){menuStatus = false});
          }
    });

    $('.pages').live("swiperight", function(){
        if (!menuStatus){   
        $(".ui-page-active").animate({
            marginLeft: "265px",
          }, 300, function(){menuStatus = true});
          }
    });

    $("#menu li a").click(function(){
        var p = $(this).parent();
        if($(p).hasClass('active')){
            $("#menu li").removeClass('active');
        } else {
            $("#menu li").removeClass('active');
            $(p).addClass('active');
        }
    });

});

这是body标签;

<body> 
        <div id="menu">
        <h3>Menu</h3>
            <ul data-role="listview" data-theme="d">
                <li data-icon="delete"><a href="#" data-rel="close">Close Menu</a></li>
            </ul>
        </div>

        <div data-role="page" class="pages" id="home">
            <div data-role="header">
            <a href="#"class="showMenu" data-icon="grid" data-iconpos="notext" data-shadow="false" data-iconshadow="false">Menu</a>
                <h1>Loreee</h1>
            </div><!-- /header -->
            <div data-role="content">
                <p><strong>Note: You can swipe right/left to show/close menu.</strong></p>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </p>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
            </div><!-- /content -->
            <div data-role="footer" data-position="fixed">
                <h1>footer</h1> 
            </div>  
        </div><!-- /page -->
</body>

等待你的答案。感谢。

2 个答案:

答案 0 :(得分:7)

.live替换为.on,如此。变化

$('.pages').live("swipeleft", function(){

$(document).on("swipeleft", ".pages", function() {
    //code here
});

答案 1 :(得分:0)

要找出不兼容问题,可以使用jquery migrate工具:

<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>