使用纯 CSS 进行 3D 变换

发布于 2024-11-18 19:23:41 字数 398 浏览 1 评论 0原文

我正在尝试用纯CSS重建 this 。我已经了。但正如您从 Flash 版本中看到的那样,当封面出现时,其他 div 会为悬停的 div 腾出空间。

我尝试将宽度设置为自动,并在该特定 div 上设置了过渡属性,但没有成功。我还尝试在悬停之前将 div 的宽度设置为 0,并在悬停时将其设置为 300px,这确实达到了目的,但它并没有真正实现动画。

它可能很简单,也可能不是,但无论哪种方式都很好朝着正确的方向推动!

谢谢。

I am trying to rebuild this with pure css. And I've got this far. But the idea as you can see from the flash version, is that as the cover appears the other divs make space for the one that is on hover.

I have tried to set the width on auto and have set the transitioning property on that particular div, but with no luck. I also tried to set the div's width to 0 before hover, and set it to 300px on hover, this did the trick but it did not really animate..

It could be something simple, or maybe not, but either way would be great to get a push in the right direction!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南月 2024-11-25 19:23:41

您不需要 WebGL 浏览器,您可以通过简单的 3D 转换来完成此操作。

当您悬停时,您必须显式更改 div 的宽度,因为显式转换不会触发重新布局。您需要对本书的内容进行绝对定位。

您应该使用包装 div 来更改悬停宽度,并使用子 div 来进行转换。

嵌套是转变理智的关键。

这是显示其实际效果的 jsfiddle: http://jsfiddle.net/ZMqze/4/

需要多一点润色才能实现悬停。

You don't need a WebGL browser you can do this with plain 3D transforms.

You have to explicitly change the width of the divs when you hover because transforms explicitly don't trigger relayout. You'll need to position the contents of the book absolutely.

You should use a wrapper div for the hover width change and a child div for the transform.

Nesting is key to transform sanity.

Here is the jsfiddle that shows it in action: http://jsfiddle.net/ZMqze/4/

needs a little more polish for unhover.

梦罢 2024-11-25 19:23:41

您可以使用 CSS3 中的 3D 变换功能。它将使您获得您想要的效果。您可以创建两个

。一个用于正面,另一个用于背面。使用z-index使正面与背面重叠,并使用position:absolute将它们放在同一位置。还可以通过设置 backface-visibilty: none 来使其背面不可见。然后将它们包裹在

中,并为其添加翻转动画。
将脚蹼包裹在

.container {
    perspective: 1000;
}

透视中将允许动画为 3D(确保使用供应商前缀)。

.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;
    position: relative;
}

翻转器必须具有相对位置,因为内部的两个元素将相互重叠并且将处于绝对位置(确保将供应商前缀添加到过渡和过渡样式)。

.container:hover .flipper{
    transform: rotateY(180deg);
}

然后,您只需添加这段代码即可使翻转器在将鼠标悬停在其包装上时翻转。
此视频教程将有所帮助:http://www.youtube.com/watch?v=6ObIO -SjMZc

You can use 3D transformation features in CSS3. It will allow you to get your desired effect. You can create two <div>s. One for the front face and another for the back face. Make front face overlap the back face by using z-index and put them in the same position by using position: absolute. Also make their backface invisible by setting backface-visibilty: none. Then wrap them up in <div class="flipper"> and add the flip animations to this.
Wrap the flipper inside <div class="container">

.container {
    perspective: 1000;
}

Perspective will allow the animation to be 3D(make sure to use vendor prefixes).

.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;
    position: relative;
}

The flipper must have position relative because the two elements inside will be overlapping each other and will have been position absolute(make sure to add vendor prefixes to transition and transition-style).

.container:hover .flipper{
    transform: rotateY(180deg);
}

Then you can just add this piece of code to make the flipper flip upon hover over its wrapper.
This video tutorial will help: http://www.youtube.com/watch?v=6ObIO-SjMZc

谢绝鈎搭 2024-11-25 19:23:41

首先,您需要一个支持硬件加速的 webgl 浏览器(仅支持 windowsxp 下的 safari5,顺便说一句。以及适用于 linux 或 win7 的 webkitnightly custombuild)

  • 将侧面和封面放在一个名为wrapper 的 div 中,该 div 具有转换属性的过渡(像 1s 缓动左右)
  • 您必须通过绕 Y 轴旋转 90 度来“隐藏”封面,
  • 添加一个自行旋转 -90 度的包装器:悬停类围绕 Y 轴

,如果我稍后有更多时间,我会尝试为您提供准确的 css,但这些说明应该会引导您获得所需的结果。

first off, you need a webgl browser that supports hardware acceleration (thats only safari5 under windowsxp, btw. and webkitnightly custombuild for linux - or win7)

  • Put the side and the cover within a single div called wrapper that has a transition for the transform property (with like 1s easing or so)
  • You have to "hide" the cover by rotating 90deg arround the Y axis
  • add a wrapper:hover class that rotates itself -90deg arround the Y axis

if I have some more time later on, I'll try to give you the exact css, but these instructions should lead you to your desired result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文