构建步骤进度条(css 和 jquery)
您已经在 paypal 等网站上看到过此类进度条的迭代。如何使用 CSS
和 jquery
进行设置?我有 4 页,每页都是一个步骤...所以 4 个步骤。
You've seen iterations of this type of progress bar on sites like paypal. How does one go about setting this up using CSS
and jquery
? I have 4 pages and each page is a step... so 4 steps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我一直在寻找一种能够可视化 Web 应用程序中的流程步骤的解决方案。我发现了 Stephen A Thomas 的以下精彩文章:
Tracking Progress in Pure CSS (原始链接现已失效)
在 Thomas 的方法中甚至只使用 CSS 就可以逃脱惩罚——不使用 Javascript!
从本质上讲,他的文章中的以下 CSS 代码对我有用:
以及他的示例中的 HTML 标签(我使用 Grails GSP 页面动态生成标签和“done/todo”类):
希望它有所帮助。对我来说效果很好。
更新:以下(缩短的)版本也运行良好。
显示:表格;表格布局:固定; width: 100%
确保只要内容不溢出,列表项就会自动调整大小。无需使用data-progtrckr-steps
及其关联的 CSS。I have searched for a solution that will visualize process steps in my web application. I have found the following excellent write-up by Stephen A Thomas:
Tracking Progress in Pure CSS (Original Link now dead)
In his approach Thomas even gets away with just using CSS - no Javascript!
In an essence the following CSS code from his article does the trick for me:
As well as HTML tags from his example (I use Grails GSP pages to generate tags and 'done/todo' class dynamically):
Hope it helps. Works pretty well for me.
UPDATE: The following (shortened) version also works well.
display: table; table-layout: fixed; width: 100%
ensure that the list items are automatically sized equally as long as the content does not overflow. There is no need to usedata-progtrckr-steps
and its associated CSS.此页面上有很多非常好的答案,我在 google 上搜索了更多答案,但没有一个答案符合我的愿望清单上的所有复选框:
所以我混合了几个示例的代码,修复了我需要的东西,结果如下:
我使用了以下 CSS 和 HTML:
从上面的示例中可以看出,现在有两个列表项类需要注意:
active
和done
。对当前步骤使用class="active"
,对之前的所有步骤使用class="done"
。另请注意
ol
标记中的data-steps="4"
;将其设置为将正确大小应用于所有列表项的总步骤数。随意使用 JSFiddle。享受!
There are a lot of very nice answers on this page and I googled for some more, but none of the answers ticked all the checkboxes on my wish list:
So I mixed the code of several examples, fixed the things that I needed and here is the result:
I used the following CSS and HTML:
As can be seen in the example above, there are now two list item classes to take note of:
active
anddone
. Useclass="active"
for the current step, useclass="done"
for all steps before it.Also note the
data-steps="4"
in theol
tag; set this to the total number of steps to apply the correct size to all list items.Feel free to play around with the JSFiddle. Enjoy!
以下是制作方法:
http://24ways.org/2008/checking-out-progress-meters
以下是一些灵感示例:
http://www.smashingmagazine.com/2010/01/15/progress-trackers-in-web-design-examples-and-best-design-practices/
Here is how to make one:
http://24ways.org/2008/checking-out-progress-meters
Here are some inspiration examples:
http://www.smashingmagazine.com/2010/01/15/progress-trackers-in-web-design-examples-and-best-design-practices/
这就是我使用纯 CSS 和 HTML(没有 JavaScript/图像等)实现它的方法。
http://jsfiddle.net/tuPrn/
它在大多数浏览器中都会正常降级(我确实需要添加修复了 < IE9 中缺少最后一个类型的问题。
This is how I have achieved it using purely CSS and HTML (no JavaScript/images etc.).
http://jsfiddle.net/tuPrn/
It gracefully degrades in most browsers (I do need to add in a fix for lack of last-of-type in < IE9).
我有同样的要求来创建一种步骤进度跟踪器,因此我为此创建了一个 JavaScript 插件。这是此步骤进度跟踪器演示的 JsFiddle。您也可以在 GitHub 上访问其代码。
它的基本作用是,它将 json 数据(采用下面描述的特定格式)作为输入,并基于该数据创建进度跟踪器。突出显示的步骤表示已完成的步骤。
它的 html 看起来有点像下面所示的默认 CSS,但您可以根据应用程序的主题对其进行自定义。还有一个选项可以显示每个步骤的工具提示文本。
这是一些代码片段:
希望它对其他人也有用!
I had the same requirements to create a kind of step progress tracker so I created a JavaScript plugin for that purpose. Here is the JsFiddle for the demo for this step progress tracker. You can access its code on GitHub as well.
What it basically does is, it takes the json data(in a particular format described below) as input and creates the progress tracker based on that. Highlighted steps indicates the completed steps.
It's html will somewhat look like shown below with default CSS but you can customize it as per the theme of your application. There is an option to show tool-tip text for each steps as well.
Here is some code snippet for that:
Hopefully it will be useful for somebody else as well!
这就是我所做的:
HTML
CSS
Javascript/jQuery
This is what I did:
HTML
CSS
Javascript/jQuery
我调整了 @Patrick Atoon 的答案,并创建了一个剃刀组件来显示枚举中的当前状态栏。这非常有效。
Razor 组件页面 - CaseStatus.razor:
CaseStatus.razor.css:
I tweeked @Patrick Atoon answer and created a razor component to display a current status bar from an Enum. This worked really well.
Razor component page - CaseStatus.razor:
CaseStatus.razor.css:
我要做的就是使用通常用于悬停在按钮上的相同技巧。准备一张由两部分组成的图像:(1) 上半部分呈灰色,表示不完整;(2) 下半部分呈彩色,表示已完成。使用同一张图片4次来组成进度条的4个步骤,不完整的步骤顶部对齐,不完整的步骤底部对齐。
为了利用图像对齐,您必须使用图像作为 4 个 div 的背景,而不是使用 img 元素。
这是用于背景图像对齐的 CSS:
What I would do is use the same trick often use for hovering on buttons. Prepare an image that has 2 parts: (1) a top half which is greyed out, meaning incomplete, and (2) a bottom half which is colored in, meaning completed. Use the same image 4 times to make up the 4 steps of the progress bar, and align top for incomplete steps, and align bottom for incomplete steps.
In order to take advantage of image alignment, you'd have to use the image as the background for 4 divs, rather than using the img element.
This is the CSS for background image alignment: