笔记

CSS实现多层波浪效果

2018.12.10 20:51
CSS

学习自:前端每日实战:24# 视频演示如何用纯 CSS 创作出平滑的层叠海浪特效

wave.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="wave.css" >
</head>
<body>
    <div class="sea">
        <p class="title">the wave</p>
        <span class="wave"></span>
        <span class="wave"></span>
        <span class="wave"></span>
    </div>
</body>
</html>

wave.css

* {
    padding: 0;
    margin: 0;
}

html, body {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(antiquewhite, navajowhite);
}

.sea {
    width: 300px;
    height: 300px;
    background-color: whitesmoke;
    border-radius: 5px;
    background-image: linear-gradient(
        darkblue,
        rgba(255, 255, 255, 0) 80%,
        rgba(255, 255, 255, 0.5)
    );
    box-shadow: 0 2px 30px rgba(0, 0,  0, 0.2);
    position: relative;
}

.sea .title {
    color: white;
    font-size: 24px;
    font-family: serif;
    text-transform: uppercase;
    letter-spacing: 0.4em;
    position: absolute;
    width: 100%;
    text-align: center;
    line-height: 240px;
    z-index: 1;
}

.sea .wave {
    position: absolute;
    top: -250px;
    left: -100px;
    width: 500px;
    height: 500px;
    background-color: deepskyblue;
    border-radius: 43%;
    filter: opacity(0.4);
    animation: drift linear infinite;
    transform-origin: 50% 48%;
}

.sea .wave:nth-of-type(1) {
    animation-duration: 5s;
}

.sea .wave:nth-of-type(2) {
    animation-duration: 7s;
}

.sea .wave:nth-of-type(3) {
    animation-duration: 9s;
    background-color: orangered;
    filter: opacity(0.1);
}

@keyframes drift {
    from {
        transform: rotate(360deg);
    }
}

.sea {
    overflow: hidden;
}

效果

wave.png

快发表第一个评论吧 ~