栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

CSS3 旋转立方体问题详解

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

3D坐标概念



 

  • 当元素进行旋转时,他的坐标轴也跟着他进行旋转
  • 注意-y方向问题

旋转立方体的效果



 

分析

  •  一个容器包含6个div
  • position:absolute 之后6个面完全重合
  • 通过trandform:rotateX/Y/Z(),translateX/Y/Z()调整到相应位置
  • 添加transition动画效果
  • 注意这里面的旋转是绕着他的中心线进行旋转的所以唯一100px
  • 他在旋转时,他的坐标轴也是跟着他进行旋转的(这很重要)

代码




    
    
    
    document
    
 *{
     margin: 0px;
     padding: 0px;

 }
 body{
     perspective: 800px;
     background: #000000;
 }
 #container{
     height: 200px;
     width: 200px;
     margin: 100px auto 0;
     position: relative;
     transform-style: preserve-3d;
     animation: move 1s ease infinite;

 }
 @keyframes move{
     from{
  transform: rotateY(0deg) rotateZ(0deg);
     }
     to{
  transform: rotateY(360deg) rotateZ(360deg);
     }
     
 }
 #container>div{
     height: 100%;
     width: 100%;
     border-radius: 5px;
     background: rgba(255,255,255,0.5);
     position: absolute;
     left: 0px;
     right: 0px;
     text-align: center;
     line-height: 200px;
     font-size: 30px;
 }
 #one{
     transform:rotateX(-90deg) translateZ(100px);
 }
 #two{
     transform:translateZ(100px) ;
 }
 #three{
     transform: rotateY(-90deg) translateZ(100px);
 }
 #four{
     transform: rotateY(-180deg) translateZ(100px);
 }
 #five{
     transform: rotateY(90deg) translateZ(100px);
 }
 #six{
     transform: translateZ(-100px);
 }
 
    


    
 1
 2
 3
 4
 5
 6
    

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/214930.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号