Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

css - Animate text fill from left to right

I wanted to animate a the text fill with CSS. The Text should be filled with color from left to right.

this is my CSS:

.box-with-text {
    background-image: -webkit-linear-gradient(right, crimson 50%, white 50%);
    background-repeat: repeat;
    background-position: 0 0;
    background-size: 200% 100%;
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    -webkit-animation: stripes normal forwards ease-in-out;
    animation: stripes 2s normal forwards ease-in-out;
}

Now only the first letter is color-filled.

here is the fiddle

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you may also take a look at flex (for centering things) and mix-blend-mode, so it can be avalaible also for Firefox:

.box-with-text {
  text-transform: uppercase;
  font: bold 26vmax/.8 Open Sans, Impact;
  background: black;
  display: table;
  color: white;
  mix-blend-mode: multiply
}

@-webkit-keyframes stripes {
  to {
    background-size:100% 100%;
  }
}

@keyframes stripes {
  to {
    background-size:100% 100%;
  }
}

html {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align:center;
  -webkit-align-items:center;
      -ms-flex-align:center;
          align-items:center;
  height: 100%;
  background: black;
}

body {
  margin: auto;
  background: -webkit-linear-gradient( crimson , crimson) turquoise no-repeat 0 0;
  background: linear-gradient( crimson , crimson) turquoise no-repeat 0 0;
  background-size: 0 100%;
  -webkit-animation: stripes 2s linear infinite;
          animation: stripes 2s linear infinite;
}
<div class="box-with-text">
  Text
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...