【CSS】How to animate the underline of text horizontally only once(Demo page)

※Please check using Developer tools

Dummytext01

Sponsored links

CSS

.wrap {
  width: 768px;
  margin: 0 auto;
  text-align: center;
}
.text {
  display: inline-block;
  position: relative;
  overflow: hidden;
  margin: 200px auto 0;
  padding: 0 0 20px;
  font-size: 50px;
}
.text:before,.text:after {
  position: absolute;
  bottom: 0;
  opacity: 0;
  transform: translateX(-100%);
  content: ' ';
  display: block;
  width: 100%;
  height: 2px;
  background: #000;
}
.active.text:before {
  transition: 0.8s cubic-bezier(0.82, 0.01, 0.28, 0.99) 0.8s;
  opacity: 1;
  transform: translateX(110%);
}

.active.text:after {
  transition: 1s cubic-bezier(0.82, 0.01, 0.28, 0.99) 1.2s;
  opacity: 1;
  transform: translateX(0%);
}

@media screen and (max-width:640px){
  .wrap {
    width: 100%;
  }
}
  

JavaScript

$(window).on('load', function(){
  $(".text").addClass("active");
});