Front-end daily combat: # 24 video demonstrates how to create a smooth wave effects layered with pure CSS

image description

Results preview

Press the right "click the Preview" button to preview the current page, click on the link to full-screen preview.

https://codepen.io/comehope/pen/JvmBdE

Interactive video tutorials

This video is interactive, you can pause the code video, editing video.

Please use chrome, safari, edge open view.

https://scrimba.com/p/pEgDAM/cp2edUD

Source code download

Daily front-end combat series full source code can be downloaded from github:

https://github.com/comehope/front-end-daily-challenges

Code Reading

Defined dom, line of text contained in the container and making waves effects <span> 3 Section:

<div class="sea">
    <p class="title">the sea</p>
    <span class="wave"></span>
    <span class="wave"></span>
    <span class="wave"></span>
</div>

Centered:

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

Setting container style:

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

Setting text style:

.sea {
    position: relative;
}

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

Making waves animation:

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

.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;
}

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

Increase the volatility of the waves, increased color differences:

.sea .wave {
    transform-origin: 50% 48%;
}

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

Finally, hidden content outside the container:

.sea {
    overflow: hidden;
}

We're done!

Guess you like

Origin www.cnblogs.com/homehtml/p/11921284.html