skip to Main Content

I’m a little stumped trying to sort out a simple animation of a background-image fading in and out on hover. Seemingly the web browser says undefined though my keyframes are defined:

  .elementor-section.elementor-element.core-range
     > .elementor-container:hover
     .product-image::before {
     animation: coreRangeBackground 0.3s ease-in-out 0.3s;
     animation-fill-mode: forwards;
  }

  @keyframes coreRangeBackground {
     100% { background-image: url("./images/core-range-bg.svg"); }
  }

  .elementor-section.elementor-element.phases-of-the-moon
     > .elementor-container:hover
     .product-image::before {
     animation-name: phasesMoonBackground;
     animation-duration: 0.3s;
     animation-timing-function: ease-in-out;
     animation-delay: 0.3s;
     animation-fill-mode: forwards;
  }

  @keyframes phasesMoonBackground {
     100% { background-image: url("./images/phases-of-the-moon-bg.svg"); }
  }

EDIT: Can’t animate background images, swapped to opacity

The image fades in with the ease, but after unhover it just instantly flicks to no image instead of easing out.

  .elementor-section.elementor-element.product-card
     > .elementor-container
     .product-image::before {
     transition: all 0.3s ease-in-out;
     position: absolute;
     width: 100%;
     height: 100%;
     background-repeat: no-repeat;
     background-size: cover;
     top: 0;
     left: 0;
     display: block;
     content: "";
  }

  .elementor-section.elementor-element.core-range
     > .elementor-container:hover
     .product-image::before {
     animation: productCardBackgroundHover 0.3s ease-in-out;
     animation-fill-mode: forwards;
     background-image: url("./images/core-range-bg.svg");
  }

  .elementor-section.elementor-element.phases-of-the-moon
     > .elementor-container:hover
     .product-image::before {
     animation: productCardBackgroundHover 0.3s ease-in-out;
     animation-fill-mode: forwards;
     background-image: url("./images/phases-of-the-moon-bg.svg");
  }

  @keyframes productCardBackgroundHover {
     0% { opacity: 0; }
     100% { opacity: 1; }
  }

2

Answers


  1. Chosen as BEST ANSWER

    So the issue was the fact the opacity wasn't transitioning, it was because I was setting the background images on hover, so when not hovered it was transitioning out the opacity, however, the image naturally instantly disappeared:

      .elementor-section.elementor-element.product-card
         > .elementor-container
         .product-image::before {
         transition: opacity 0.3s ease-in-out;
         position: absolute;
         width: 100%;
         height: 100%;
         background-repeat: no-repeat;
         background-size: cover;
         top: 0;
         left: 0;
         display: block;
         content: "";
         opacity: 0;
      }
    
      .elementor-section.elementor-element.core-range
         > .elementor-container
         .product-image::before {
         background-image: url("./images/core-range-bg.svg");
      }
    
      .elementor-section.elementor-element.core-range
         > .elementor-container:hover
         .product-image::before, 
      .elementor-section.elementor-element.phases-of-the-moon
         > .elementor-container:hover
         .product-image::before {
         opacity: 1;
      }
    
      .elementor-section.elementor-element.phases-of-the-moon
         > .elementor-container
         .product-image::before {
         background-image: url("./images/phases-of-the-moon-bg.svg");
      }
    

  2. Place the two @keyframes definitions are placed at the beginning.
    I think it will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search