JQuery 滚动/分页选项卡

发布于 2024-08-05 22:29:46 字数 357 浏览 2 评论 0原文

我正在尝试为一个网站创建一个简单的选项卡栏,该网站能够滚动不适合页面的选项卡。这非常简单,不需要任何 ajax 或动态加载的内容...它只是显示所有选项卡,当您单击一个选项卡时,它会将您带到另一个页面。

我已经在互联网上搜索过,但似乎找不到除以下内容之外的任何内容: http://www.extjs.com/deploy/dev/examples /tabs/tabs-adv.html 然而,这是非常繁重和复杂的...我正在寻找 jquery 中的一个轻量级示例。如果有人可以帮助我,我将不胜感激!

I am trying to create a simple tab bar for a site that has the ability to scroll for tabs that do not fit on the page. This is quite simple and does not need to have any ajax or dynamically loaded content...it simply displays all the tabs, and when you click one, it takes you to another page.

I have scoured the internet and can not seem to find anything other than:
http://www.extjs.com/deploy/dev/examples/tabs/tabs-adv.html
however this is very heavy and complicated...I am looking for a lightweight example in jquery. If anyone can help I would be grateful!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

节枝 2024-08-12 22:29:46

我最终自己用一个 div 编写了它,该 div 的溢出设置为隐藏。然后使用下面的jquery来移动div中的选项卡。

    $(document).ready(function()
    {
      $('.scrollButtons .left').click(function()
      {
        var content = $(".tabs .scrollable .content")
        var pos = content.position().left + 250;
        if (pos >= 0)
        {
            pos = 0;
        }
        content.animate({ left: pos }, 1000);
      });
      $('.scrollButtons .right').click(function()
      {
        var content = $(".tabs .scrollable .content")
        var width = content.children('ul').width();
        var pos = content.position().left - 250;
        //var width = content.width();
        if (pos <= (width * -1) + 670)
        {
            pos = (width * -1) + 600;
        }
        content.animate({ left: pos }, 1000);
      });
    });

我的 Html 看起来像这样:

    <div class="tabs">
    <div class="scrollable">
        <div class="content">
            <ul>
                <li>Tab1</li>
                <li>Tab2</li>
                <li>Tab3</li>
                <li>Tab4</li>
                <li>Tab5</li>                    
                </ul>
        </div>
    </div>
    <div class="scrollButtons">
        <ul>
            <li>
                <div class="left">
                </div>
            </li>
            <li>
                <div class="right">
                </div>
            </li>
        </ul>
    </div>
</div>

I ended up writing it myself with a div who's overflow is set to hidden. Then used the jquery below to move the tabs in the div.

    $(document).ready(function()
    {
      $('.scrollButtons .left').click(function()
      {
        var content = $(".tabs .scrollable .content")
        var pos = content.position().left + 250;
        if (pos >= 0)
        {
            pos = 0;
        }
        content.animate({ left: pos }, 1000);
      });
      $('.scrollButtons .right').click(function()
      {
        var content = $(".tabs .scrollable .content")
        var width = content.children('ul').width();
        var pos = content.position().left - 250;
        //var width = content.width();
        if (pos <= (width * -1) + 670)
        {
            pos = (width * -1) + 600;
        }
        content.animate({ left: pos }, 1000);
      });
    });

My Html looked like this:

    <div class="tabs">
    <div class="scrollable">
        <div class="content">
            <ul>
                <li>Tab1</li>
                <li>Tab2</li>
                <li>Tab3</li>
                <li>Tab4</li>
                <li>Tab5</li>                    
                </ul>
        </div>
    </div>
    <div class="scrollButtons">
        <ul>
            <li>
                <div class="left">
                </div>
            </li>
            <li>
                <div class="right">
                </div>
            </li>
        </ul>
    </div>
</div>
路弥 2024-08-12 22:29:46

我刚刚自己创建了一个插件:
项目主页:http://jquery.aamirafridi.com/jst

I have just created a plugin myself:
Project home: http://jquery.aamirafridi.com/jst

当梦初醒 2024-08-12 22:29:46

您可以简单地将选项卡包装在 DIV 中,并在 CSS 中设置overflow-x: auto 吗?

Could you simply wrap the tabs in a DIV with overflow-x: auto set in the CSS?

趴在窗边数星星i 2024-08-12 22:29:46

我总是使用 JQuery UI 选项卡 作为选项卡的起点。您可以在网站的下载部分自定义 JQuery UI 下载。如果您已在网站上使用 JQuery,则此方法应该比任何其他实现更轻。

开箱即用的 JQuery UI 选项卡不会为您提供所需的滚动功能。我相信这可以通过更改 CSS 来实现,但如果您更改网站的导航(即创建更多级别,使用更短的标题),则可能会更容易。

希望这有帮助

I always use JQuery UI tabs as a starting point for tabs. You can customize the JQuery UI download in the download section of the website. This method should be lighter than any other implementation, if you are already using JQuery on your website.

Out of the box, the JQuery UI tabs will not give you the scrolling you desire. This I believe could be achieved by altering the CSS, but more than likely will be easier if you alter the navigation of your site (i.e. create more levels, use shorter titles).

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文