How to use pure CSS to implement a banner-like animation effect (with source)

Source: Internet
Author: User
This article brings you the content is about how to use the pure CSS to achieve similar to the banner of the animation effect (with source), there is a certain reference value, the need for friends can refer to, I hope to help you.

Effect Preview

Source code Download

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

Code interpretation

To define the DOM, the container contains 15 elements:

<div class= "Flag" >    <span></span>    <span></span>    <span></span >    <span></span>    <span></span>    <span></span>    <span ></span>    <span></span>    <span></span>    <span></span>    <span></span>    <span></span>    <span></span>    <span ></span>    <span></span></div>

Center display:

body {    margin:0;    HEIGHT:100VH;    Display:flex;    Align-items:center;    Justify-content:center;    Background-color:black;}

Define Container Dimensions:

. flag {    width:10em;    height:15em;    font-size:20px;}

To set the line style:

. flag span {    width:0.25em;    Height:inherit;    Background-color:deepskyblue;}

To tile a line:

. flag {    Display:flex;    Justify-content:space-between;}

Add 3d Perspective Effect:

. flag {    transform:perspective (500px) Rotatey ( -20deg);}

Define animation effects for moving left and right:

. flag span {    animation:wave 1.5s ease-in-out infinite Alternate;} @keyframes Wave {to    {        Transform:translatex (2EM);    }}

To set the value of an element variable:

. Flag Span:nth-child (1) {    --n:1;}. Flag Span:nth-child (2) {    --n:2;} /* A total of 15 elements, the value of the--n variable for each element equals its ordinal number. *//* Intermediate code slightly ... */.flag span:nth-child () {    --n:14;}. Flag Span:nth-child {    --n:15;}

Let each line start the animation, respectively, the effect of the flag fluttering:

. flag span {    Animation-delay:calc (var (--n) * -0.1s);}

Finally, increase the lighting effect:

. flag span {    background-color:ghostwhite;} @keyframes Wave {to    {        Transform:translatex (2EM);        Background-color:deepskyblue;}    }

Done!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.