简体   繁体   中英

how to mimic jquery UI tabs

I have a need to use the tabs in my jquery mobile application. I looked at the navbars in jquerymobile but it opens a totally different page. Whereas jquery UI opens the tabs in the same page. Is there any way I can mimic that behavior. thanks

Please notice that I am asking to, for the lack of better term, transform the behavior of navbars of jquerymobile to that of UI tabs

Here is a sample of how to mimic tab behaviour using navbar.It is a basic thing only and needs more work to make it perfect.But I think it can serve as a starting point.

<!DOCTYPE html> 
<html> 
    <head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script>
        var prevSelection = "tab1";
        $("#navbar ul li").live("click",function(){
            var newSelection = $(this).children("a").attr("data-tab-class");
            $("."+prevSelection).addClass("ui-screen-hidden");
            $("."+newSelection).removeClass("ui-screen-hidden");
            prevSelection = newSelection;
        });
    </script>
    <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
    <style>
        .tab-content{
            width:100%;
            height:250px;
            background-color:white;
            border-bottom-left-radius:0.5em;
            border-bottom-right-radius:0.5em;
        }
        .tab-content>div{
            padding:5px;
        }                   

    </style>
    </head> 

    <body> 
        <div data-role="page">

        <div data-role="header">
        <h1>My Title</h1>
        </div><!-- /header -->

        <div data-role="content">   
            <div data-role="navbar" id="navbar">
                <ul>
                    <li><a href="#" class="ui-btn-active" data-tab-class="tab1">Tab1</a></li>
                    <li><a href="#" data-tab-class="tab2">Tab2</a></li>
                    <li><a href="#" data-tab-class="tab3">Tab3</a></li>
                    <li><a href="#" data-tab-class="tab4">Tab4</a></li>
                </ul>
            </div>
            <div class="tab-content">
                <div class="tab1">
                    Tab1
                </div>
                <div class="tab2 ui-screen-hidden">
                    Tab2
                </div>
                <div class="tab3 ui-screen-hidden">
                    Tab3
                </div>
                <div class="tab4 ui-screen-hidden">
                    Tab4
                </div>
            </div>
        </div><!-- /content -->

        </div><!-- /page -->
    </body>
</html>

A demo here - http://jsfiddle.net/m8wQM/

Let me know if it helps.

try this work-in-progress JQM extension: http://www.stokkers.mobi/jqm/tabview/tab.html

It's a mix of JQM grids and collapsible-sets. I'm working on an update (no min-height reqs, highlighted tab color, 1,2,3,4,5 tabs), but will be a while until I put it on Github. When it's done, I'll repost here, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM