How to make HTML/CSS slideshow background fade?

后端 未结 2 2019
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 22:09

I was wondering how you make a background slideshow fade into other photos like a regular slideshow. I\'ve tried many codes and have yet to be successful.

Now, I hav

相关标签:
2条回答
  • 2021-01-12 22:34

    Working example on jsFiddle.

    Use this code instead: (note that you'll need to load jQuery in order for this code to work)

    HTML

    <div class="fadein">
        <img src="http://farm9.staticflickr.com/8359/8450229021_9d660578b4_n.jpg">
        <img src="http://farm9.staticflickr.com/8510/8452880627_0e673b24d8_n.jpg">
        <img src="http://farm9.staticflickr.com/8108/8456552856_a843b7a5e1_n.jpg">
        <img src="http://farm9.staticflickr.com/8230/8457936603_f2c8f48691_n.jpg">
        <img src="http://farm9.staticflickr.com/8329/8447290659_02c4765928_n.jpg">
    </div>
    

    CSS

    .fadein {
        position:relative;
        height:320px;
        width:320px;
    }
    
    .fadein img {
        position:absolute;
        left:0;
        top:0;
    }
    

    JavaScript

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
    $('.fadein img:gt(0)').hide();
    
    setInterval(function () {
        $('.fadein :first-child').fadeOut()
                                 .next('img')
                                 .fadeIn()
                                 .end()
                                 .appendTo('.fadein');
    }, 4000); // 4 seconds
    });
    </script>
    
    0 讨论(0)
  • 2021-01-12 22:36

    Inside the Css:

    width: 100%; height: 100%; position: fixed;

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