如何对很多很多页面进行页面导航?对数页面导航
显示许多页面的页面导航的最佳方式是什么?
(最初这是作为操作提示发布的,我的答案包含在问题中。我现在将我的答案分成下面的“答案”部分)。
更具体地说:
假设您要向用户显示一组记录,这些记录分为固定大小的页面(例如 Google 搜索的结果)。如果只有几个页面,您可以在结果末尾显示页面导航区域,可能如下所示:
[ << ] [<] 1 2 3 4 5 6 7 8 9 10 11 12 13 [ > ] [>> ]
但如果结果超过 20 或 30 页,这很快就会变得不方便。
有时你会看到这样的东西:
[ << ] [<] ... 665 666 667 668 669 670 671 672 673 ... [ > ] [>> ]
或这个:
[ << ] [<] 1 2 3 ... 667 668 669 670 671 ... 845 846 847 [ > ] [>> ]
但在这两种情况下,导航到“...”部分中间的任何位置都需要多次单击鼠标。有时会提供直接输入页码的输入框;否则(假设我们在这里讨论的是网页)精明的用户可能会查看 URL 以查看是否可以直接编辑它。
如果有一个分页显示,让用户只需点击几下鼠标就可以到达任何页面,而不需要有太多的链接,那就太好了。
如何最好地实现这一目标?
What's the best way of displaying page navigation for many, many pages?
(Initially this was posted as a how-to tip with my answer included in the question. I've now split my answer off into the "answers" section below).
To be more specific:
Suppose you're displaying a set of records to the user, broken up into fixed-size pages (like the results of a Google search, for example). If there are only a few pages, you can display a page navigation area at the end of the results that might look like this:
[ << ] [<] 1 2 3 4 5 6 7 8 9 10 11 12 13 [ > ] [ >> ]
But this quickly becomes unweildy if there are much more than 20 or 30 pages of results.
Sometimes you'll see things like this:
[ << ] [<] ... 665 666 667 668 669 670 671 672 673 ... [ > ] [ >> ]
or this:
[ << ] [<] 1 2 3 ... 667 668 669 670 671 ... 845 846 847 [ > ] [ >> ]
but in both cases, navigating to anywhere in the middle of the "..." sections would take many, many mousclicks. Sometimes an input box for entering the page number directly is provided; otherwise (assuming we're talking about a webpage here) the savvy user is likely to look at the URL to see if they can edit it directly.
What would be nice would be to have a pagination display that lets the user reach any page in only a few mouseclicks, without having ridiculously many links.
How would that best be achieved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我的解决方案 - 使用“对数页面导航”:
这可以通过根据距端点或当前页面的距离以对数方式分布页码来实现。这是我的意思的一个例子:
1 2 3 4 5 6 。 10. 20. 30 . 40. 50 .. 100 .. 200 . 210. 220. 230. 240. 250. 252 253 254 255 256 257 258 259 260 261 262 。 270. 280. 290. 300 . 310 .. 400 .. 500 .. 600 .. 700 .. 800 .. 900 .. 950 .. 960. 970. 980. 990. 995 996 997 998 999 1000
请注意,在间隙中,编号如何从 1 变为 10,再变为 100(等等)。 (我使用 10 的幂,但原则上你可以使用不同的方案 - 比如说 2 的幂)。
我在 2004 年编写了一些执行此操作的代码,并认为我应该在这里分享它。有 PHP 和 ASP 版本,但逻辑应该很简单,可以翻译成任何语言。请注意,底部的位(在两种情况下)仅显示一些示例。显然,格式需要自定义才能匹配您的网页(或应用程序),因此这里的格式非常基本。更改
paginationHTML
中的LINKS_PER_STEP
以确定当您离开端点或当前页面时步长增加之前显示的数字数量。为了获得更紧凑的输出,您还可以考虑更改代码,以使端点周围的编号不会“密集”(即仅在当前页面周围密集)。
代码如下:
PHP 版本:
ASP 版本:
Javascript 版本(在完整的测试页内):
Here's my solution - use "Logarithmic Page Navigation":
This can be achieved by having page numbers distributed logarithmically, according to distance from either the endpoints or the current page. Here's an example of what I mean:
1 2 3 4 5 6 . 10 . 20 . 30 . 40 . 50 .. 100 .. 200 . 210 . 220 . 230 . 240 . 250 . 252 253 254 255 256 257 258 259 260 261 262 . 270 . 280 . 290 . 300 . 310 .. 400 .. 500 .. 600 .. 700 .. 800 .. 900 .. 950 . 960 . 970 . 980 . 990 . 995 996 997 998 999 1000
Notice how in the gaps, numbering goes from 1s, to 10s, to 100s (etc.). (I use powers of 10, but in principle you could use a different scheme - powers of 2, say).
I wrote some code that does this back in 2004, and thought I'd share it here. There are PHP and ASP versions, but the logic ought to be simple to translate into any language. Note that the bit at the bottom (in both cases) just displays some examples. Obviously the formatting will need customization to match your webpage (or application), so it's pretty basic here. Alter
LINKS_PER_STEP
inpaginationHTML
to determine how many numbers get displayed before the step size increases, as you move away from the endpoints or current page.For a more compact output you could also consider altering the code so that the numbering is not "dense" around the endpoints (i.e. dense only around the current page).
Here's the code:
PHP version:
ASP version:
Javascript version (within complete test page):
JavaScript 中“对数页面导航”的简化版本:
生成下拉菜单。这个示例只是 document.write 而已,但您可以根据您的需要进一步开发它(添加 onChange 等)。 Javascript 转换感谢 http://www.basereality.com/PHPToJavascript。
Simplified version of "Logarithmic Page Navigation" in JavaScript:
Generates dropdown menu. This sample just document.write's it but you can develop it further according to your need (add onChange, etc). Javascript conversion thanks to http://www.basereality.com/PHPToJavascript.
怎么样:
a) 添加 <-100 <-10 [分页] +10> +100>不要破坏分页本身
b) 提供直接页面输入 [# .. ] [ view ] ,根据有效页面范围过滤输入
c) 需要一些适当的编码,但是:通过说 +/ 扩展内部浮动范围-10、+/-25、+/-100 页,而不是放大整个分页范围
How about:
a) add <-100 <-10 [pagination] +10> +100> instead of blow up the pagination itself
b) offer a direct page input [# .. ] [ view ] , filter the input against the valid page range
c) needs some proper coding, but: expand the inner, floating range by say +/-10, +/-25, +/-100 page instead of blowing up the complete paging range
我想到了对数分页的两种替代方案:
如果相关,您可以将数据拆分为部分、章节和书籍。这是古老的方式,当时纸张为王,图书馆取代了互联网的工作。一些 PDF 文档仍然有这样的内容。
如果有人想跳转到提到
supercalifragilisticexpialidocious
的大数据部分,您可以提供一个搜索框,如维基百科。I think of two alternatives of logarithmic pagination:
If relevant, you could split your data in sections, chapters and books. This is the old way, when paper was king, and libraries made the job of internet. Some PDF documents still have that.
You can offer a search box, ala Wikipedia, if someone wants to jump to the part of big-data where
supercalifragilisticexpialidocious
is mentioned.