transform 3d学习&简单示例

  • 平移:transform: tranlateX(x) | tranlateY(y) | translateZ(z) | translate3d(x, y, z);
  • 比例:transform: scaleX(x) | scaleY(y) | scaleZ(z) | scale3d(x, y, z);
  • 旋转:transform: rotateX(1) | rotateY(1) | rotateZ(1) | rotate3d(1, 1, 1, 45deg);
  • 函数写法,以上都可以写成下面这种形式:transform: matrix3d(...);
  • transform-style: preserve-3d;
    父元素必须设置该属性才能开启3d空间
  • perspective: 1000px;
    透视距离。表示人眼到屏幕的距离,值越小,图越大

示例写3d旋转

css 复制代码
 <div className={styles.box}>
       <li className={styles.li}></li>
        <li className={styles.li}></li>
        <li className={styles.li}></li>
        <li className={styles.li}></li>
        <li className={styles.li}></li>
        <li className={styles.li}></li>
    </div>
css 复制代码
.box {
    position: relative;
    width: 500px;
    height: 300px;
    transform-style: preserve-3d;
    /* background: #eee; */
    /* perspective: 1000px; */ 
    animation: move 10s linear infinite;
    animation-play-state: paused;
    transform: rotateX(60deg);
}

.box:hover {
    animation-play-state: running;
}

.li {
    list-style: none;
    width: 100px;
    height: 200px;
    position: absolute;
    left: 200px;
    top: 50px;
    box-shadow: 0 0 10px 0 #fff;
}

.li:nth-child(1){
    background: red;
    transform: rotateY(0deg) translateZ(100px);
}
.li:nth-child(2){
    background: orange;
    transform: rotateY(60deg) translateZ(100px);
}
.li:nth-child(3){
    background: blue;
    transform: rotateY(120deg) translateZ(100px);
}
.li:nth-child(4){
    background: green;
    transform: rotateY(180deg) translateZ(100px);
}
.li:nth-child(5){
    background: yellow;
    transform: rotateY(240deg) translateZ(100px);
}
.li:nth-child(6){
    background: purple;
    transform: rotateY(300deg) translateZ(100px);
}

@keyframes move {
    0% { transform: rotateX(-20deg) rotateY(0deg); }
    100% { transform: rotateX(-20deg) rotateY(360deg); }
}

效果

相关推荐
W.A委员会10 小时前
CSS中的单位
css·css3·html5
爱上好庆祝17 小时前
学习js的第五天
前端·css·学习·html·css3·js
W.A委员会18 小时前
让元素不显示的方法
css3
DFT计算杂谈2 天前
VASP官方教程 TRIQS DFT+DMFT计算教程
运维·css·自动化·html·css3
遇见~未来2 天前
第五篇_构建真实页面_组件_响应式_维护性
前端·css3
遇见~未来3 天前
第三篇_现代布局_从弹性到网格
前端·css3
遇见~未来3 天前
第四篇_强化视觉_字体_动画_变换
前端·css3
琹箐4 天前
今天吃什么干什么随机生成
javascript·css·css3
AZaLEan__6 天前
Flex 弹性布局学习总结
前端·css·css3
爱上好庆祝6 天前
学习js的第四天
前端·css·学习·html·css3·js