前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >translateZ()——动画示例

translateZ()——动画示例

作者头像
Html5知典
发布2019-11-26 14:32:05
1K0
发布2019-11-26 14:32:05
举报
文章被收录于专栏:Html5知典Html5知典

用途

translateZ() 规定Z轴Z上的移动。

语法

代码语言:javascript
复制
translateZ(t)

描述

t

规定Z轴的移动距离。

例子

代码语言:javascript
复制
/* HTML */
<div class="stage"> 
    <div class="positioning animated"> 
        <div class="monitor"> 
            <figure class="back">back</figure> 
            <figure class="front">front</figure> 
        </div> 
    </div> 
 </div>
 
 /* CSS */
.monitor .front { 
     height: 80px; 
     width: 100px; 
     background: #e0e0e0; 
     transform: translateZ(40px);//旋转轴的 Z 坐标 50个像素。 } 
.monitor .back { 
    height: 80px; 
    width: 100px; 
    background: linear-gradient(top, #f2f2f2, #e6e6e6 2.5px, #c2c2c2); 
    transform: translateZ(-40px) rotateY(180deg); //旋转轴的 Z 坐标 -40个像素。与 Y 坐标180度。 } 
.stage { 
    width: 100%; 
    height: 150px; 
    position: relative; 
    perspective: 1600px;
    perspective-origin: 50% 100px; 
    background: #333; } 
.positioning { 
    position: absolute; 
    width: 90px; 
    top: 30px; 
    left: 50%; 
    margin-left: -45px; 
    transform-style: preserve-3d; 
    transform: rotateY(-40deg); } 
.positioning.animated { 
    animation: back-and-forth 14s ease-in-out infinite; } 
.monitor { 
    width: 120px; 
    height: 100px; 
    margin: 0 auto; 
    transform-style: preserve-3d; } 
.monitor figure, .monitor span { 
    display: block; 
    position: absolute; 
    opacity: 1; } 
figure { 
    text-align: center; 
    font-size: 30px; 
    font-family: Helvetica, Arial, Sans-serif; 
    color: red; 
    line-height: 80px; } 
@keyframes back-and-forth { 
    0% {transform: rotateY(40deg); } 
    40%, 50% {transform: rotateY(-40deg); } 
    90%, 100% {transform: rotateY(40deg); } 
} 
@keyframes flash { 
    0% { opacity: 0; } 
    49.9% { opacity: 0; } 
    50%, 100% { opacity: 1; } 
}

执行结果

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Html5知典 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档