fade in and fade out in pure javascript without jquery

后端 未结 4 1317
情深已故
情深已故 2021-01-05 10:13

Here I have a function that fades a square box with id=\"box\" as soon as the page loads. I tried but failed to find out how to fade in the box again or simply

4条回答
  •  Happy的楠姐
    2021-01-05 10:21

    I'd suggest using CSS animation

    @-webkit-keyframes fadeout {
        0% {opacity:1;}
        100% {opacity:0;}
    }
    @keyframes fadeout {
        0% {opacity:1;}
        100% {opacity:0;}
    }
    .fadeOut {
      opacity:0;
      -moz-animation   : fadeout 1s linear;
      -webkit-animation: fadeout 1s linear;
      animation        : fadeout 1s linear;
    }
    

    You only need to add fadeOut class to the element

提交回复
热议问题