12

我一直在寻找文档,但似乎找不到在jQuery mobile中制作可滚动水平导航栏的方法,有人完成了吗?

到目前为止,这就是我的导航栏

<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>
4

5 回答 5

21

我想这就是你想要的。

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;
    });         
});
于 2011-11-24T14:25:17.330 回答
2

另外,试试: http: //kryops.de/jqm/tabs/demo

这看起来非常有希望,并且在移动设备上的性能非常好。

于 2014-06-10T05:24:43.210 回答
1

我知道这不是你要找的,但是:

现场示例: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>

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

更新了示例:http: //jsfiddle.net/9zuxH/21/ 好一点

于 2011-04-21T01:55:49.383 回答
0

在研究同一问题时偶然发现了这一点。还没试过,但看起来很方便

http://darsa.in/sly/

于 2014-03-27T18:32:07.630 回答
0

这是在 ypur lst 评论之后,所以我将解决用手指滚动导航栏的需要。

您指出了一个有问题的实现。还有其他的。我曾经使用过这个:http: //plugins.jquery.com/project/jQclickNScroll 用于桌面触摸屏。(不确定它在移动设备上的行为)它与 hrefs 一起使用,并且它有一个选项allowHiliting:true可以关闭以防止其他事件通过

还有这个: http ://digitalillusion.altervista.org/wordpress/pages/dragscroller/viewport-test.html

于 2011-09-20T07:40:10.880 回答