Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQM horizontal scroll navbar

i"ve been hunting the docs and can't seem to find a way to make a scrollable horizontal navbar in jQuery mobile has anybody accomplished this yet ?

here's what i have for navbar so far

<div data-role="header" data-scroll="x">
    <ul>
        <li class="logo"><a href="#"><img src="img/iphoneheader.gif" alt="Penn State Live" /></a></li>
        <li id="link"><a href="#type=colleges">Colleges</a></li>
        <li><a href="#">Campuses</a></li>
        <li><a href="#">Faculty and Staff</a></li>
        <li><a href="#">Of Interest</a></li>
        <li><a href="#">Photos</a></li>
        <li><a href="#">Video</a></li>
        <li><a href="#">Newswire Subscription</a></li>
        <li><a href="#">PSUTXT</a></li>
    </ul>
</div>
like image 423
mcgrailm Avatar asked Apr 21 '11 01:04

mcgrailm


3 Answers

I guess this is what you want.

HTML.

    <div class="categories">                
            <ul>                    
                <li><span><a href="">ABC</a></span></li>
                <li><span><a href="">DEF</a></span></li>
                <li><span><a href="">GHI</a></span></li>
                <li><span><a href="">JKL</a></span></li>
            </ul>               
        </div>

JQuery

$(function(){           
    var step = 1;
    var current = 0;
    var maximum = $(".categories ul li").size();
    var visible = 2;
    var speed = 500;
    var liSize = 120;
    var height = 60;    
    var ulSize = liSize * maximum;
    var divSize = liSize * visible; 

    $('.categories').css("width", "auto").css("height", height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
    $(".categories ul li").css("list-style","none").css("display","inline");
    $(".categories ul").css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute").css("white-space","nowrap").css("margin","0px").css("padding","5px");

    $(".categories").swipeleft(function(event){
        if(current + step < 0 || current + step > maximum - visible) {return; }
        else {
            current = current + step;
            $('.categories ul').animate({left: -(liSize * current)}, speed, null);
        }
        return false;
    });

    $(".categories").swiperight(function(){
        if(current - step < 0 || current - step > maximum - visible) {return; }
        else {
            current = current - step;
            $('.categories ul').animate({left: -(liSize * current)}, speed, null);
        }
        return false;
    });         
});
like image 57
Umar Maniar Avatar answered Nov 20 '22 17:11

Umar Maniar


Also, try out: http://kryops.de/jqm/tabs/demo

This looks really promising and performance is great on mobile.

like image 2
Paul Avatar answered Nov 20 '22 16:11

Paul


I know it's not what you're looking for but:

Live Example: http://jsfiddle.net/9zuxH/10/

<div data-role="page" data-theme="b" id="jqm-home">
    <ul >
        <li data-role="fieldcontain"> 
            <fieldset data-role="controlgroup" data-type="horizontal">
                <div class="logo"><a href="#"><img src="img/iphoneheader.gif" alt="Penn State Live" /></a></div>
                <div id="link"><a href="#type=colleges">Colleges</a></div>
                <a href="#">Campuses</a>
                <a href="#">Faculty and Staff</a>
                <a href="#">Of Interest</a>
                <a href="#">Photos</a>
                <a href="#">Video</a>
                <a href="#">Newswire Subscription</a>
                <a href="#">PSUTXT</a>
            </fieldset>
        </li>
    </ul>
</div>

Documentation: jquerymobile.com/demos/1.0a4.1/docs/lists/lists-forms-inset.html

UPDATED the example: http://jsfiddle.net/9zuxH/21/ A little better

like image 1
Phill Pafford Avatar answered Nov 20 '22 16:11

Phill Pafford