Can I fade in a background image (CSS: background-image) with jQuery?

后端 未结 9 1169
一生所求
一生所求 2020-11-29 00:52

I have a div element with text in it and a background image, which is set via the CSS property background-image. Is it possible to fade in the back

9条回答
  •  星月不相逢
    2020-11-29 01:24

    This is what worked for my, and its pure css


    css

    html {
        padding: 0;
        margin: 0;
        width: 100%;
        height: 100%;
      }
    
      body {
        padding: 0;
        margin: 0;
        width: 100%;
        height: 100%;
      }
    
      #bg {
        width: 100%;
        height: 100%;
        background: url('/image.jpg/') no-repeat center center fixed;
    
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    
        -webkit-animation: myfirst 5s ; /* Chrome, Safari, Opera */
        animation: myfirst 5s ;
      }
    
      /* Chrome, Safari, Opera */
      @-webkit-keyframes myfirst {
        from {opacity: 0.2;}
        to {opacity: 1;}
      }
    
      /* Standard syntax */
      @keyframes myfirst {
        from {opacity: 0.2;}
        to {opacity: 1;}
      }
    

    html

    
    
    
        
    
    
      

提交回复
热议问题