【CSS】How to implement an animation that moves the color linearly from left to right in the background using Transform | Demo page

※Please check using Developer tools

Sponsored links

CSS

.block {
  position: relative;
  margin: 50px auto 0;
}

.block:before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  display: block;
  width: 100%;
  height: 300px;
  transform: translateX(-100%);
  transition: transform 1s ease-out;
  background: #efefef;
}

.active.block:before {
  transform: translateX(0);
}

.img {
  position: relative;
  width: 600px;
  line-height: 0;
  margin: 0 auto;
  z-index: 1;
}

@media screen and (max-width:640px){
  .block {
    width: 100%;
  }
  .block:before {
    height: 150px;
  }
  .img {
    width: 80%;
  }
}

JavaScript

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