CSS3 to achieve text sweep effect

Source: Internet
Author: User

This post consists of: http://xinpure.com/css3-text-light-sweep-effect/

CSS3 implementation of the text sweep effect, almost comparable to Flash

Effect analysis

Let's analyze the functionality required to achieve this effect:

    1. Implement a sweep background block because the light is moving, so add a gradient effect (for example: a small piece of area illuminated by a flashlight)

    2. Control the sweep background block to text (that is, to implement the text background)

    3. Implement sweep animation (sweep blocks move from left to right)

The idea is clear, the next step is to achieve the

Background gradient-webkit-linear-gradient (form sweep background block)
background: #111 -webkit-linear-gradient(left, #111, #fff) 0 0 no-repeat;background-size: 80px

The default background is black, a black and white gradient is created from left to right, the background is in the upper left corner, not duplicated, and the background size 80x80 (sweep background block)

Background range-webkit-background-clip (implements text background)

In order to realize the text sweep, we must take the sweep background block formed in the previous step, control the text above

background-clipThere are three properties: Border-box, Padding-box, Content-box (Specific effect not detailed)

Obviously these attributes do not meet our needs, and there are no attributes that can control the text background.

However webkit background-clip , there is a property that is usually used in conjunction with background-clip: text its private properties -webkit-text-fill-color (fill text color)

Background animation (sweep animation)
@-webkit-keyframes slideShine {    0% {        background-position: 0 0;    }    100% {        background-position: 100% 100%;    }}

The sweep effect is achieved by adjusting the position of the background (left to right)

Effect instance CSS Code
.bg {     background: #000;    width: 1000px;    height: 300px;    margin: 0 auto;    padding-top: 100px;}.slideShine {    width: 1000px;    font-family: "Microsoft YaHei";    font-size: 60px;    text-align: center;    background: #111 -webkit-linear-gradient(left, #111, #fff) 0 0 no-repeat;    background-size: 80px;    -webkit-background-clip: text;    -webkit-text-fill-color: rgba(255, 255, 255, 0.3);    -webkit-animation: slideShine 3s infinite;}@-webkit-keyframes slideShine {    0% {        background-position: 0 0;    }    100% {        background-position: 100% 100%;    }}
HTML Code
<div class="bg">    <p class="slideShine">Welcome to xinpureZhu Blog</p></div>
Effect illustration

CSS3 to achieve text sweep effect

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.