介绍css 的3D 变换(3D transform)

https://desandro.github.io/3dtransforms/docs/card-flip.html

---------------------------------------------------------------------------------------------------

Card Flip

We now have all the tools to start making 3D objects. Let’s get started with the basics, flipping a card.

Here’s the basic markup we’ll need:

<section class="container">
  <div id="card">
    <figure class="front">1</figure>
    <figure class="back">2</figure>
  </div>
</section>

The .container will house the 3D space. The #card acts as a wrapper for the 3D object. Two separate elements for both faces of the card, .front and .back. Even for such a simple object, I recommend using this same pattern for any 3D transform. Keeping the 3D space element and the object separate element establishes a paradigm that is simple to understand and easier to style.

We’re ready for some 3D stylin’. First, apply necessary perspective to the parent 3D space, along with any size or positioning styles.

.container {
  width: 200px;
  height: 260px;
  position: relative;
  perspective: 800px;
}

Now the #card element can be transformed in its parent’s 3D space. We’re using absolute/relative positioning so the 3D object is removed from the flow of the document. We’ll also add @width: 100%; and height: 100%;@. This ensures the object’s transform-origin will occur in the center of container. More on transform-origin later.

Let’s add a CSS3 transition so users can see the transform take effect.

#card {
  width: 100%;
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  transition: transform 1s;
}

The .container’s perspective only applies to direct descendant children, in this case #card. In order for subsequent children to inherit a parent’s perspective, and live in the same 3D space, the parent can pass along its perspective with transform-style: preserve-3d. Without 3D transform-style, the faces of the card would be flattened with its parents and the back face’s rotation would be nullified.

To position the faces in 3D space, we’ll need to reset their positions in 2D with position: absolute. In order to hide the back-side of the faces when they are faced away from the viewer, we use backface-visibility: hidden.

#card figure {
  margin: 0;
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
}

To flip the .back face, we add a basic 3D transform of rotateY( 180deg ).

#card .front {
  background: red;
}
#card .back {
  background: blue;
  transform: rotateY( 180deg );
}

With the faces in place, the #card requires a corresponding style for when it is flipped.

#card.flipped {
  transform: rotateY( 180deg );
}

Now we have a working 3D object. To flip the card, we can toggle the flipped class. When .flipped, the #card will rotate 180 degrees, thus exposing the .back face.

See Example: Card 1

Slide-flip

Take another look at the Weather App 3D transition. You’ll notice that it’s not quite the same effect as our previous demo. If you follow the right edge of the card, you’ll find that it stays flush with the container. Instead of pivoting from the horizontal center, it pivots on that right edge. But the transition is not just a rotation – the edge moves horizontally from right to left. We can reproduce this transition just by modifying a couple lines of CSS from our original card flip demo.

The pivot point for the rotation occurs at the right side of the card. By default, the transform-origin of an element is at its horizontal and vertical center (50% 50% or center center). Let’s change it to the right side:

#card { transform-origin: right center; }

That flip now needs some horizontal movement with translateX. We’ll set the rotation to -180deg so it flips right side out.

#card.flipped {
  transform: translateX( -100% ) rotateY( -180deg );
}

See Example: Card 2

时间: 2024-11-11 18:38:07

介绍css 的3D 变换(3D transform)的相关文章

Web 前端技术:CSS3---新属性,浏览器支持度,圆角边框(border-radius),阴影(box-shadow),文字与字体(text-shadow属性、word-wrap属性、@font-face规则),2D转换、过渡与动画(transform属性),3D变换

浏览器支持度 CSS3属性: columns:规定列的宽度和列数 默认宽度.列数值为auto column-width:每栏的宽度 column-gap :两栏之间的间距距离 column-count : 栏目的数目 column-rule : color(色值) width(宽度) style(线条样式) 分栏中的分割线的颜色宽度及样式的设定 1.border-radius属性(圆角边框) eg: 结合不同浏览器兼容问题,使用该CSS3新属性 eg: 2.box-shadow属性(阴影) eg

CSS3 3D变换实例 滚动的正方体

笔记: 2D变换 transform 位移   translateX() translateY()  简写:translate(X值,Y值)  正值向右,负值向左 旋转 rotate()  rotate(?deg)  括号中为角度值   正值是顺时针旋转,负值是逆时针旋转 缩放 scale()  scale() 括号中为数值,可以为浮点数     如大于1是放大效果,小于1是缩小效果 变形(斜切)  skewX() skewY() 简写:skew(X轴斜切角度,Y轴斜切角度) body:hove

CSS 3D transform(CSS的3D变换)

src1:好吧,CSS3 3D transform变换,不过如此! 评价:图文并茂地解释 CSS 3D transform 的基本概念及原理,超级通俗易懂,读后简直醍醐灌顶啊!!!幽默的程序员 笔记: 一.4个概念 1.突破口:三个方法  3D transform 中的三个方法: (1)rotateX(angle):正面推倒 (2)rotateY(angle):左右转 (3)rotateZ(angle):横抱躺着 2.必不可少的perspective(透视.视角) 没透视,不3D CSS 3D

基本3D变换之World Transform, View Transform and Projection Transform

作者:i_dovelemon 来源:CSDN 日期:2014 / 9 / 28 主题:World Transform, View Transform , Projection Transform 引言 在3D图形学中,基本几何变换是一个非常重要的操作.可以说,整个3D图形能够有效的显示,就是由于几个非常重要的基础3D变换贡献的.在前面的文章中,向大家承诺了,要详细的讲解在3D图形学中的三个基本的坐标变换.今天,就来像大家讲述,DirectX是如何进行变换. 变换的目的 在我们讲解具体的变换工作之

css之3D变换

3D变换的x,y,z轴是分别效果是: x轴旋转的话,就是头和脚进行转动 y轴旋转的话,就是左右手进行转动 z轴旋转的话,就是整个身体平铺在旋转. 上面是针对旋转的意思去,但是对于其他的类似一样,就是这样子去理解x,y,z轴的在哪里的 transform: rotateX(360deg); transform: rotateY(360deg); transform: rotateZ(360deg); 变换跟2D同理 最主要的区别是透视视图"景深" <!--景深的作用: 1.让3D场

(一一九)通过CALayer实现阴影、圆角、边框和3D变换

在每个View上都有一个CALayer作为父图层,View的内容作为子层显示,通过layer的contents属性决定了要显示的内容,通过修改过layer的一些属性可以实现一些华丽的效果. [阴影和圆角] 下面以一个普通的蓝色View为例,介绍layer的功能: _blueView.layer.shadowOpacity = 1.0; // 阴影不透明度 _blueView.layer.shadowColor = [UIColor redColor].CGColor; // 注意所有颜色都要转换

CSS3之3d变换与关键帧

3d变换是在transform基础上实现的 transform-style:preserve-3d; 建立3d空间 perspective:; 景深(设置用户看的距离) perspective-origin:center center;(默认) 景深基点(设置用户从哪个方向看) backface-visility 隐藏背面 -transform:; 在3d中新增了以下函数: rotateX() rotateY() rotateZ() translateZ() scaleZ() 注: X表示屏幕水

css3 3D变换和动画

3D变换和动画 建立3D空间,transform-style: preserve-3d perspective: 100px; 景深 perspective-origin:center center -180px;  景深基点 transform新增函数如下: rotateX(); rotateY(); rotateZ(); translateZ(); scaleZ(); 3d动画demo,只支持Webkit内核,可自行运行查看效果 <!DOCTYPE HTML> <html> &

第1部分: 游戏引擎介绍, 渲染和构造3D世界

原文作者:Jake Simpson译者: 向海Email:[email protected] ------------------------------------------------------------第1部分: 游戏引擎介绍, 渲染和构造3D世界 介绍 自Doom游戏时代以来我们已经走了很远. DOOM不只是一款伟大的游戏,它同时也开创了一种新的游戏编程模式: 游戏 "引擎". 这种模块化,可伸缩和扩展的设计观念可以让游戏玩家和程序设计者深入到游戏核心,用新的模型,场景和

WPF 3D 小小小小引擎 - &#183;WPF 3D变换应用

原文:WPF 3D 小小小小引擎 - ·WPF 3D变换应用 WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开发效率高,而且也容易上手. 下面给大家演示的是使用在WPF 3D上实现视角变换,通过鼠标拖动来变换观察视角,通过滚轮来放缩视距. 有关3D的基础知识可以参考MSDN文档:三维图形概述 首先创建一个3D立方体,立方体是由六个面构成(F1, F2 ....F6)其XAML代码如下: <Viewport3