Crossfade two images repeatedly after showing for 10 seconds

后端 未结 1 1437
死守一世寂寞
死守一世寂寞 2021-01-27 07:10

I\'m trying to use HTML and CSS to crossfade two images after showing them for 10 seconds each. I want this to repeat constantly.

Here is my HTML:



        
相关标签:
1条回答
  • 2021-01-27 07:32

    Here is an example with 10s delay and 1s animation duration.

    #container {
      float: right;
      height: 246px;
      position: relative;
      width: 230px;
    }
    #container img {
      height: 246px;
      width: 230px;
      left: 0;
      opacity: 0;
      position: absolute;
    }
    #container img.bottom {
      opacity: 1;
    }
    #container img.top {
      -webkit-animation: crossFade 11s infinite;
      animation: crossFade 11s infinite;
      -webkit-animation-direction: alternate;
      animation-direction: alternate;
    }
    
    @-webkit-keyframes crossFade {
      0% {
        opacity: 0;
      }
      47.62% {
        opacity: 0;
      }
      52.38% {
        opacity: 1;
      }
      100% {
        opacity: 1;
      }
    }
    @keyframes crossFade {
      0% {
        opacity: 0;
      }
      47.62% {
        opacity: 0;
      }
      52.38% {
        opacity: 1;
      }
      100% {
        opacity: 1;
      }
    }
    <div id="container">
      <img class="bottom" src="https://dummyimage.com/200x200/404/fff">
      <img class="top" src="https://dummyimage.com/200x200/101/fff">
    </div>

    0 讨论(0)
提交回复
热议问题