CSS3 background image transition

前端 未结 13 2336
梦如初夏
梦如初夏 2020-11-22 07:07

I\'m trying to make a \"fade-in fade-out\" effect using the CSS transition. But I can\'t get this to work with the background image...

The CSS:



        
13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 07:55

    If animating opacity is not an option, you can also animate background-size.

    For example, I used this CSS to set a backgound-image with a delay.

    .before {
      background-size: 0;
    }
    
    .after {
      transition: background 0.1s step-end;
      background-image: $path-to-image;
      background-size: 20px 20px;
    }
    

提交回复
热议问题