6.HTML + CSS —— 立體旋轉小球

在這裏插入圖片描述

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>立體旋轉小球</title>
    <link rel="stylesheet" href="css/5-28.css">
</head>

<body>
    <div id="box">
        <div class='wrap' id='wrap1'>
            <div class='ball' id='ball1'></div>
        </div>
        <div class='wrap' id='wrap2'>
            <div class='ball' id='ball2'></div>
        </div>
    </div>
</body>

</html>

css部分:

* {
    margin: 0;
    padding: 0;
}

body {
    background-color: #262626;
}

#box {
    width: 150px;
    height: 50px;
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    margin: auto;
    opacity: 0;
    animation: fadeIn 1s 1;
    animation-fill-mode: forwards;
}

.wrap {
    animation: translate 1000ms infinite ease-in-out alternate, zindex 2000ms infinite ease-in-out;
    position: absolute;
}

.ball {
    width: 50px;
    height: 50px;
    box-shadow: 0 -6.25px 0 rgba(0, 0, 0, 0.15) inset;
    background-color: purple;
    border-radius: 50%;
    animation: scale 1000ms infinite ease-in-out alternate;
    animation-delay: -500ms;
    transform: scale(0.5);
    border: 2px solid black;
}

.ball:after {
    content: '';
    width: 50px;
    height: 13px;
    background: #eee;
    position: absolute;
    top: 70px;
    border-radius: 50%;
}

#wrap2 {
    animation-delay: -1000ms;
}

#ball2 {
    background-color: #fff000;
    animation-delay: -1500ms;
}

@keyframes translate {
    100% {
        transform: translateX(100px);
    }
}

@keyframes scale {
    100% {
        transform: scale(1);
    }
}

@keyframes zindex {
    25% {
        z-index: 1;
    }
    75% {
        z-index: -1;
    }
}

@keyframes fadeIn {
    100% {
        opacity: 1;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章