简体   繁体   English

如何在HTML / CSS中标记速度表/仪表?

[英]How to mark up speedometer/gauge in HTML/CSS?

As a front-end developer, I've been given a mock-up design to implement. 作为一名前端开发人员,我获得了一个模拟设计来实现。 This design features several tachograph-style icons, which have me stumped as to the best way to mark them up in HTML and CSS. 这个设计有几个行车记录仪式的图标,让我难以理解在HTML和CSS中标记它们的最佳方式。

The images look like the following: 图像如下所示:

在此输入图像描述在此输入图像描述

Obviously these assets represent the empty state and the full state respectively. 显然,这些资产分别代表空状态和满状态。

My issue is this: how can I mark-up these images so that I can show varying levels of completion, ie 10% full, 60% full etc? 我的问题是:我如何标记这些图像,以便我可以显示不同的完成程度,即10%满,60%满等?

Waiting in anticipation to hear your answers. 等待期待听到你的答案。

I would seriously recommend looking into the Raphael javascript library. 我会认真推荐调查Raphael javascript库。 You can knock something like this up in just a few lines of code. 你可以用几行代码敲出这样的东西。

See also this question: Drawing a half gauge/speedometer (JavaScript Canvas or Java Swing Example needed) where I gave an answer including a four-line code sample using Raphael, which provides an animated fuel gauge. 另请参阅此问题: 绘制半量规/速度表(需要JavaScript Canvas或Java Swing示例) ,我在其中给出了一个答案,其中包括使用Raphael的四行代码示例,该示例提供了动画燃油表。 You'll need to tweak it for your design, but even then it's only going to be a few lines of code. 你需要为你的设计调整它,但即便如此,它只会是几行代码。

The great thing about using Raphael to draw things like this is that it is fully compatible with older browsers, even IE (as far back as IE6 if you need it), without you having to do any special code to support it. 使用Raphael绘制这样的东西的好处在于它与旧版浏览器完全兼容,甚至IE(如果你需要的话,可以追溯到IE6),而不需要做任何特殊的代码来支持它。 It's a great little library. 这是一个很棒的小图书馆。

Hope that helps. 希望有所帮助。

Given that the image reprisents actual data and isn't purely a design mechanism, I'd mark the image up as an HTML image. 鉴于图像重现实际数据并且不是纯粹的设计机制,我将图像标记为HTML图像。

<img ... alt="10%">

If your concern is about showing portions of the image, one way you could do this would be to set the image as a background to some container and use width and height to identify the amount of the image to show. 如果您关注的是显示图像的某些部分,您可以采用的一种方法是将图像设置为某个容器的背景,并使用宽度和高度来标识要显示的图像数量。

i'm not an expert on html5 /css3, but would you not use the html5 arc command to create a mask to reveal the full state. 我不是html5 / css3的专家,但你不会使用html5 arc命令创建一个掩码来显示完整状态。

As you have a 270 degree rotation from empty to full, you'd just map the value as percentage of 270 to create the value of the arc that would mask the appropriate value. 当你从空到满旋转270度时,你只需要将值映射为270的百分比,以创建掩盖适当值的弧的值。

I believe that there is a java script Math.PI that might help to. 我相信有一个可能有用的java脚本Math.PI。

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

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