简体   繁体   English

如何实现像“水平滚动导航栏”这样的分页?

[英]How to implement Pagination like a “Horizontal Scrolling Navigation Bar”?

I'm trying to create a bottom aligned navigation bar that contains "prev" and "next" buttons for moving through a list of links, something similar to what you might see at the bottom of a long forum thread. 我正在尝试创建一个底部对齐的导航栏,其中包含“prev”和“next”按钮,用于浏览链接列表,类似于您在长论坛帖子底部看到的内容。

The number of links will vary through different sections of the site and I'd like to be able to fix the number of links (6 plus prev + next buttons) displayed at any one time. 链接的数量会因网站的不同部分而有所不同,我希望能够确定任何时候显示的链接数量(6加上prev +下一个按钮)。 There would always be more than 6 links to display (minimum 15). 将始终显示超过6个链接(最少15个)。

This is what I want to achieve: 这就是我想要实现的目标:

在此输入图像描述

There's not much HTML and I don't have any other code (apart from some aesthetic stylings which aren't really relevant). 没有太多的HTML,我没有任何其他代码(除了一些不相关的美学风格)。 I'm happy to use any combination of CSS and JavaScript that could make this work. 我很高兴使用可以使这项工作的CSS和JavaScript的任何组合。

My HTML is as follows: 我的HTML如下:

<div class="bottom_nav page_width">
        <ul>
            <li><a href="#"><i class="icon-chevron-left icon-large"></i></a></li>
            <li><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
            <li><a href="#">4</a></li>
            <li><a href="#">5</a></li>
            <li><a href="#">6</a></li>
            <li><a href="#">7</a></li>
            <li><a href="#">8</a></li>
            <li><a href="#">9</a></li>
            <li><a href="#">10</a></li>
            <li><a href="#">11</a></li>
            <li><a href="#">12</a></li>
            <li><a href="#">13</a></li>
            <li><a href="#">14</a></li>
            <li><a href="#">15</a></li>
            <li><a href="#">16</a></li>
            <li><a href="#"><i class="icon-chevron-right icon-large"></i></a></li>
        </ul>
    </div>

Firstly you can use CSS property white-space:nowrap; 首先你可以使用CSS属性white-space:nowrap; to align all the links in one single line. 将所有链接对齐在一行中。

That will enable the horizontal scrollbar which you can hide by using overflow: hidden; 这将启用水平滚动条,您可以使用overflow: hidden;

Now you can use a JavaScript function that can scroll the content of the div or ul . 现在您可以使用可以滚动divul内容的JavaScript函数。 It may be scrollBy(x, y) . 它可能是scrollBy(x, y)

This is how you can achieve what you want to, as I understood your question. 正如我理解你的问题,这就是你如何实现自己想要的目标。 If not, please explain with images or a better description. 如果没有,请说明图片或更好的描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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