jQuery Mobile Navigation Tabs

前端 未结 6 971
遇见更好的自我
遇见更好的自我 2020-12-25 15:39

I want to have a tab-navigation in my jQuery Mobile project. I know I can use the data-role \'navbar\' but I only want to change the content below that navbar without swipin

6条回答
  •  遥遥无期
    2020-12-25 15:54

    UPDATE: Check out my jsfiddle at http://jsfiddle.net/ryanhaney/eLENj/

    I just spent some time figuring this out, so I thought I would answer this. Note I am using multi-page single file, YMMV.

    
    
    $("div[data-role=page]").bind("pagebeforeshow", function () {
        // prevents a jumping "fixed" navbar
        $.mobile.silentScroll(0);
    });
    
    $("a[data-role=tab]").each(function () {
            // bind to click of each anchor
            var anchor = $(this);
            anchor.bind("click", function () {
                // change the page, optionally with transitions
                // but DON'T navigate...
                $.mobile.changePage(anchor.attr("href"), {
                    transition: "none",
                    changeHash: false
            });
    
            // cancel the click event
            return false;
        });
    });
    

提交回复
热议问题