css硬币旋转和立方体旋转动画

主要是对于animation和transform的综合应用
transform是基于图形变换
animation是可以生成不间断的动画
transform-style: preserve-3d;用来保证3d的背面效果
css硬币旋转和立方体旋转动画_第1张图片
css硬币旋转和立方体旋转动画_第2张图片

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>硬币旋转</title>
    <style>
        .coin>div{
            position: absolute;
            width:100%;
            height:100%;
        }
        img{
            width:100%;
            height:100%;
            border-radius: 50%;
        }
        @keyframes rotate{
            0%{
                transform: rotateY(0deg);
            }
            100%{
                transform: rotateY(360deg);
            }
        }
        .coin{
            width:100px;
            height:100px;
            transform-style: preserve-3d;/*不写就不会显示背面的图片*/
            animation: rotate 3s linear infinite;
        }
    </style>
</head>
<body>
    <div class="coin">
        <div class="front" style="transform: translateZ(3px);">
            <!-- transform: translateZ(3px)表示前后位移,这里能显示出厚度 -->
            <img src="https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture" alt="正面">
        </div>
        <div class="reverse">
            <img src="https://uploadbeta.com/api/pictures/random/" alt="反面">
        </div>
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>立方体</title>
    <style>
        @keyframes rotate {
            0% {
                transform: rotateY(0deg) rotateX(0deg);
            }

            100% {
                transform: rotateY(-360deg) rotateX(-180deg);
            }
        }
        .cube .m {
            position: absolute;
            width: 200px;
            height: 200px;
            opacity: 0.9;
        }
        .cube{
            position: absolute;
            left:30%;
            top:30%;
            width: 200px;
            height: 200px;
            transform-style: preserve-3d;
            animation: rotate 10s linear infinite;
            line-height: 200px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="cube">
        <div class="m" style="background-color: aliceblue; transform: translateZ(100px);">1</div>
        <div class="m" style="background-color: antiquewhite; transform: rotateY(90deg) translateZ(100px);">2</div>
        <div class="m" style="background-color: aqua; transform: rotateX(90deg) translateZ(100px);">3</div>
        <div class="m" style="background-color: aquamarine; transform: rotateX(-90deg) translateZ(100px);">4</div>
        <div class="m" style="background-color: azure;transform: rotateY(-90deg) translateZ(100px);" >5</div>
        <div class="m" style="background-color: bisque; transform: rotateY(-180deg) translateZ(100px)">6</div>
    </div>
</body>

</html>

你可能感兴趣的:(前端,css3,animation,css,html)