【CSS】How to implement a curtain animation that displays text by sliding a rectangular color over text(Demo page)

※Please check using Developer tools

Dummytext01

スポンサーリンク

JavaScript

$(function(){
  $('.curtain').addClass('active');
});

CSS

.text {
  margin: 200px 0 0;
  text-align: center;
  font-size: 50px;
}

.curtain {
  position: relative;
}

.curtain span {
  transition: all 0s 2s ease;
  opacity: 0;
}

.curtain.active span {
  opacity: 1;
}

.curtain:after {
  display: inline;
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  background: #2f2e2e;
}

.curtain.active:after {
  animation: curtain 1s ease 1.5s 1 normal both running;
}

@keyframes curtain {
  0% {
    transform-origin: left center;
    transform: scaleX(0)
  }

  49.999% {
    transform-origin: left center;
    transform: scaleX(1)
  }

  50% {
    transform-origin: right center;
    transform: scaleX(1)
  }

  100% {
    transform-origin: right center;
    transform: scaleX(0)
  }
}
@media screen and (max-width:640px){
  .text {
    font-size: 30px;
  }
}