Firefox 3.5 中的 3D 变换 – 等轴测立方体

此演示由来自明尼苏达州明尼阿波利斯的 Web 开发人员 Zachary Johnson 创建,他还为 动画“3D”旋转 创建了一个 jQuery 插件。

我想展示一个使用 Firefox 3.5 浏览器中可用的新 -moz-transform CSS 变换属性可以实现的可视效果示例。看到 Firefox 添加了此功能,我非常兴奋,因为我知道它可以让我产生伪 3D 等轴测效果,有时也称为 2.5D。我创建了一个演示,其中 HTML 内容映射到“3D”等轴测立方体的面上

在 Firefox 3.5 中查看演示
isocube

-moz-transform 属性可以采用 CSS 变换函数列表,包括旋转、缩放、倾斜和平移。或者,可以使用单个 2D 仿射变换矩阵同时执行多个变换。由于所有 CSS 变换函数都在二维空间中工作,因此尚无法实现具有透视投影的真正 3D 变换。在此演示中,我使用旋转和倾斜变换函数来创建 等轴测 效果。

首先,我为立方体定义一个容器 div,然后为立方体的顶部、左侧和右侧定义一个正方形 div。

.cube {
    position: absolute;
}

.face {
    position: absolute;
    width: 200px;
    height: 200px;
}

在不深入等轴测投影数学的情况下,我们必须旋转和倾斜立方体的面,以便将每个正方形 div 变成一个平行四边形,其中顶点的角度为 60° 或 120°。以下是使用新的 -moz-transform CSS 属性表示的这些变换

.top {
    -moz-transform: rotate(-45deg) skew(15deg, 15deg);
}

.left {
    -moz-transform: rotate(15deg) skew(15deg, 15deg);
}

.right {
    -moz-transform: rotate(-15deg) skew(-15deg, -15deg);
}

现在剩下的就是使用绝对定位将每个变换后的 div 连接起来,以形成等轴测立方体的面。您可以使用矩阵数学来执行此操作,或者您也可以将面四处移动,直到它们对齐并看起来正确为止。

为了增强 3D 效果,我通过为面分配不同的颜色来对等轴测立方体进行阴影处理。我还给立方体添加了一个阴影。您可以看到,阴影基本上只是立方体顶面的副本,向下移动到左下角,然后我给阴影 div 一个黑色背景颜色并在 CSS 中设置 opacity: 0.5; 以使其过滤到页面背景上。

任何 HTML(例如此示例中的文本和表单按钮)都可以放在立方体任何面的 div 内。它将转换为正确的透视。 Christopher Blizzard 给了我一个想法,可以使用 Firefox 3.5 中现在支持的新 HTML5 视频标签将视频投射到立方体的一侧。如您所见,效果非常好。

最后,通过复制立方体标记并使用另外两个 CSS 变换函数,我能够创建第二个立方体。我使用 scale(0.5) 变换使立方体的大小变为 50%,并使用 translate(600px, 400px) 将其移动到位。

我希望您觉得此演示很有趣,并且它让您对 Firefox 3.5 CSS 变换 为 Web 带来的令人兴奋的可能性有了一些了解。

Safari 3.1+ 和 Chrome 也支持 CSS 变换,使用 -webkit-transform CSS 属性。

关于 Christopher Blizzard

一次发布,让网络变得更好。

更多 Christopher Blizzard 的文章…


51 条评论

  1. Dan

    我以前从未见过这样使用变换,非常酷。我喜欢所有文本都是可选的。

    2009 年 6 月 15 日 下午 12:48

  2. Zacharias

    为什么当我选择文本时它会抖动?

    2009 年 6 月 15 日 下午 13:24

  3. Magne Andersson

    我无法看到大盒子阴影下的文本,文章中的图片是旧版本的图片,还是在 Mac 上的呈现方式不同(按钮暗示是 Mac)?

    2009 年 6 月 15 日 下午 13:49

  4. Michael Kozakewich

    jQuery 能处理这样的动画吗?我需要检查一下。如果您可以做一些疯狂的事情来旋转一个立方体以在 iframe 中显示外部网站,那将非常棒。

    您可以在侧面添加按钮来控制导航。

    2009 年 6 月 15 日 下午 13:59

  5. Pino

    哈哈,这个例子导致我的浏览器崩溃。Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.1) Gecko/20090612 Firefox/3.5。Firefox 伟大程度的一个非常糟糕的例子 :P

    2009 年 6 月 15 日 下午 14:42

  6. […] Mozilla Hacks。在 del.icio.us 上分享此内容Digg 此内容!偶然发现了一些好的内容?在 StumbleUpon 上分享此内容分享此内容 […]

    2009 年 6 月 15 日 下午 14:49

  7. Magne Andersson

    @Michael Kozakewich – 您的意思是这个吗?http://www.zachstronaut.com/lab/3d.html http://www.zachstronaut.com/projects/rotate3di/

    2009 年 6 月 15 日 下午 17:19

  8. Rowno

    哈哈,当我尝试选择框中的文本时,我的 Firefox 也崩溃了。

    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b99) Gecko/20090605 Firefox/3.5b99 (.NET CLR 3.5.30729) 在 Windows XP 上

    2009 年 6 月 15 日 下午 18:42

  9. kbrosnan

    遇到崩溃的两位用户是否可以在地址栏中键入 about:crashes 并检查崩溃 ID。将信息发布到此博客或通过 commenter name at gmail dot com 给我发送电子邮件

    http://support.mozilla.com/en-US/kb/Mozilla+Crash+Reporter#Viewing_crash_reports

    2009 年 6 月 15 日 下午 19:41

  10. g zgodero

    什么也没发生,没有操作,没有崩溃……什么也没有。

    2009 年 6 月 15 日 下午 20:17

  11. […] 3.5 nos delitará con la posibilidad de realizar tranformaciones 3D nativamente. Esta propiedad del CSS nos permitirá, entre otras cosas, dar efecto de profundidad a los […]

    2009 年 6 月 16 日 上午 00:01

  12. […] 3.5 nos delitará con la posibilidad de realizar tranformaciones 3D nativamente. Esta propiedad del CSS nos permitirá, entre otras cosas, dar efecto de profundidad a los […]

    2009 年 6 月 16 日 上午 00:40

  13. Quezako

    我第一次使用 Fx 3.5b99 点击视频时崩溃了,但我必须承认这个演示令人惊叹!

    2009 年 6 月 16 日 上午 00:54

  14. tomh

    非常酷,确实展示了一些属性的过度使用。我必须说,看到这个时我不禁想到了标签……希望能够使用此标签的人知道如何明智地使用它 ;-)

    2009 年 6 月 16 日 上午 03:25

  15. Alfred Kayser

    太棒了!不仅视频被转换了,控制栏(启用时)也被转换了!

    2009 年 6 月 16 日 上午 05:17

  16. […] 3D transforms in Firefox 3.5 – the isocube at hacks.mozilla.org […]

    2009 年 6 月 16 日 上午 05:24

  17. web 设计师

    谢谢
    会尝试一下
    我只是想知道它在 ie7 上是什么样子
    此致

    2009 年 6 月 16 日 下午 16:30

  18. Rowno

    我在等轴测立方体上两次崩溃的崩溃 ID 分别为 453109a7-8409-4c7a-aeda-176e72090615 和 f50c518f-b86d-4e34-a890-491d92090615。

    2009 年 6 月 16 日 下午 20:03

  19. […] 原文地址:3D transforms in Firefox 3.5 – the isocube 系列地址:颠覆网络35天 […]

    2009 年 6 月 16 日 下午 22:25

  20. Quezako

    66c35595-a93a-4934-bb20-4038a2090616

    2009 年 6 月 17 日 上午 01:40

  21. philoye

    仅供参考,此演示在 Mac/Safari 4 上运行良好,至少在最近的 Webkit nightly 版本中是如此。

    2009 年 6 月 17 日 上午 03:22

  22. Magne Andersson

    @Web 设计师:它在 IE7 或 IE8 中都不起作用。正如我们现在所知,微软速度缓慢,并且阻止新标准变得流行。

    2009 年 6 月 17 日 上午 04:55

  23. […] noch sehr ruckelig – einen ersten Crash hatte ich bereits nach 5 Minuten beim testen der 3D-Transformierung. Generell findet man auf hacks.mozilla.org eine ganze Menge zum rumspielen, wenn man gerade mit der […]

    2009 年 6 月 17 日 下午 14:38

  24. […] the video runs it uses the transformation property to rotate the video while it’s playing: function rotateMePlease() { // […]

    2009 年 6 月 17 日 下午 22:05

  25. […] in honor of the hacks.mozilla.org recent article called 3D transforms in Firefox 3.5 – the isocube I added a similar hack to my tabbed message example extension.  I give […]

    2009 年 6 月 18 日 下午 16:59

  26. […] in honor of the hacks.mozilla.org recent article called 3D transforms in Firefox 3.5 – the isocube I added a similar hack to my tabbed message example extension.  I give […]

    2009 年 6 月 18 日 下午 23:06

  27. Denis Seleznev

    我是 CSS 变换的粉丝! :)

    http://webfilin.ru/files/notes/text-photo/firefox/

    2009 年 6 月 19 日 上午 09:31

  28. […] the specific device characteristics such as aspect ratio, resolution, color capabilities, and more; cool 3D and image/font effects thanks to the <canvas> element; and lots of […]

    2009 年 6 月 19 日 下午 22:40

  29. Alexandre

    在 Windows Vista 64 位系统上使用 FF3.5 RC2 几秒钟后每次都会崩溃。

    2009 年 6 月 22 日 上午 06:34

  30. Alexandre

    kbrosnan:抱歉,没有崩溃 ID。看起来 Firefox 在生成报告之前就崩溃了。我会尝试通过邮件与您联系以获取更多信息。

    2009 年 6 月 22 日 上午 07:36

  31. Alexandre

    不同格式的崩溃视频(均可由 VLC 读取)
    http://alexandre.alapetite.fr/prive/temp/20090622-Firefox3.5rc2-crash-isocube-Vista64.avi
    http://alexandre.alapetite.fr/prive/temp/20090622-Firefox3.5rc2-crash-isocube-Vista64.mp4
    http://alexandre.alapetite.fr/prive/temp/20090622-Firefox3.5rc2-crash-isocube-Vista64.ogv

    2009 年 6 月 22 日 上午 09:15

  32. Quezako

    @Alexandre 您是否尝试过停用所有附加组件?
    我在 Firefox 3.5 RC2 + Windows 7 x64 上没有问题。

    2009 年 6 月 22 日 上午 11:51

  33. […] CSS 3D transforms. Try the demo, and don’t forget to select some text on the page https://hacks.mozilla.ac.cn/2009/06/3d-transforms-isocube/ […]

    2009 年 6 月 26 日 上午 00:40

  34. DarthNihilus

    在 FF 3.5 RC 3 中无法正常工作。不知何故,它们的字体相互重叠,我不知道……

    2009 年 6 月 29 日 下午 12:51

  35. […] are supported too, making it possible to rotate and skew page elements. This feature has been used experimentally to simulate isometric 3D rendering. In the following image, a playable video and selectable text […]

    2009 年 6 月 30 日 上午 10:44

  36. […] are supported too, making it possible to rotate and skew page elements. This feature has been used experimentally to simulate isometric 3D rendering. In the following image, a playable video and selectable text […]

    2009 年 7 月 1 日 上午 08:20

  37. SelenIT

    看起来很棒!谢谢,Zachary 和 Christopher!

    但我建议稍微“改进”一下:用其他 CSS3 替换立方体阴影的毫无意义的空 div(例如 -moz-box-shadow: -398px 200px 3px rgba(0, 0, 0, 0.5); 以及顶部使用 -webkit-,这在我的 Firefox 3.5、Safari 4/Win 和 Chrome 2 中有效)。

    2009 年 7 月 1 日 上午 11:04

  38. […] 3-D cubes built with standard HTML content, including the new native video component. […]

    2009 年 7 月 1 日 下午 17:26

  39. aroth

    请添加 javascript 以使立方体在 3D 中旋转。

    2009 年 7 月 3 日 下午 16:47

  40. […] are supported too, making it possible to rotate and skew page elements. This feature has been used experimentally to simulate isometric 3D rendering. In the following image, a playable video and selectable text […]

    2009 年 7 月 5 日 下午 19:13

  41. Andre

    这些属性是否有 w3c 批准的等效项

    2009 年 7 月 15 日 上午 07:34

  42. […] 写道” Safari 4浏览器核心WebKit在最近的一次更新中加入了3D CSS变换支持,FireFox 3.5也支持该特性。3D […]

    2009 年 7 月 16 日 上午 03:29

  43. […] 原文地址:3D transforms in Firefox 3.5 – the isocube 系列地址:颠覆网络35天 […]

    2009 年 7 月 23 日 下午 20:33

  44. Hdaes32

    为什么不添加非“-moz-”属性?:(
    该死的粉丝……

    2009 年 12 月 22 日 上午 03:40

  45. Magne Andersson

    @Hdaes32 这就像是在问为什么它们存在一样。在将此功能添加到 Gecko 时,规范尚未完成,因此它只能支持带有前缀的属性,就像任何其他引擎/浏览器一样。我非常确定规范目前还不够稳定。

    2009年12月22日 14:01

  46. freemh

    看起来很棒!希望它能在 Internet Explorer 上运行,这里还有一个我发现很有趣的例子
    http://depotwebdesigner.com/tutorials/how-to-create-3d-cube-with-css3.html

    2010年7月25日 05:33

  47. […] border ….. et transition http://css3pie.com/ -> idem http://selectivizr.com/ ->CSS3 pour IE https://hacks.mozilla.ac.cn/2009/06/3d-transforms-isocube/ -> la puissance de css3 permetant de creer effet 3D http://www.fontsquirrel.com/fontface ->font […]

    2011年2月24日 12:58

  48. […] 一段关于 3D 平面的视频。如果你的谈话对象坚持,不要被这种演示所迷惑:肯定有 Flash 的参与。如果有人试图向你证明这种 […]

    2011年3月20日 17:11

  49. Scott Gale

    感谢你撰写这篇文章。它帮助我在构建这个 CSS coverflow 示例时:http://scottgale.com/blog/coverflow-css-3d-transforms/2011/05/24/

    2011年5月29日 05:53

  50. Murray

    我喜欢我们可以使用这些转换选项来创建等轴测平面,但定位它们却是一场噩梦。

    “你可以使用矩阵数学来做这件事”——这显然是轻描淡写了。

    我真的很想看到一篇后续文章,重点关注自动定位不同的平面,使它们完全对齐。

    我正在使用转换来显示一个尺寸不同的盒子,每个面上都有图案和文字。所以我只需要简单的数学函数,我输入面的尺寸,它返回 HTML 的 top 和 left 值来定位该面。谁能帮忙?

    干杯
    Murray

    2011年10月24日 16:23

  51. […] Johnson 和 Paul Hayes 展示了一些 CSS 2D 转换功能的非常好的示例(isocube,使用 2D 的 3D isocube […]

    2011年10月26日 16:44

本文的评论已关闭。