Search code examples
javascripthtmlcssjquery-waypoints

Unable to show color fill animation in div when the page loads


$("#whoami").waypoint(function() {
    console.log('you have scrolled to the h1!');
   });
.d8{
    border: 1px solid black;
    width: 100%;
    height: 2.5rem;
    margin-left: 5rem;
    border-radius: 1rem;
    background: linear-gradient(to right, #e74c3c 85%, #FFF 50%);
}
<div class="d8"></div>

Now I have been trying to fill the color in the div when the waypoint reaches the particular section having some nice animation effect for the user and I am not able to achieve it though, Have tried transition effect and keyframe none seems to work, any help would be very much appreciated.


Solution

  • In you case you can animate background-size instead of background-image (that you cannot animate) and make the linear-gradient to be one color as the white part will be the part without background:

    .d8 {
      border: 1px solid black;
      width: 80%;
      height: 2.5rem;
      margin-left: 5rem;
      border-radius: 1rem;
      background-image: linear-gradient(to right, #e74c3c, #e74c3c);
      background-size: 80% 100%;
      background-repeat: no-repeat;
      transition: 0.5s;
    }
    
    .d8:hover {
      background-size: 100% 100%;
    }
    <div class="d8"></div>