Change background-image of a div with fade effect every 10 seconds with jquery

后端 未结 3 1245
难免孤独
难免孤独 2020-12-15 00:04

I would like to create a slideshow in the header area of my page. It should change the background image every 10 seconds with a nice fade effect. And since I\'m using jQuery

3条回答
  •  [愿得一人]
    2020-12-15 00:48

    I answered a similar question at How to fill browser window with rotating background Image?. You can fade background colors but not background images. You must have your images in tags and hide them by default display:none;. Give your images position:absolute and z-index:-1 so your images acts like a background images and are behind everything else.

    function test() {
        $("img").each(function(index) {
            $(this).hide();
            $(this).delay(10000 * index).fadeIn(10000).fadeOut();
        });
    }
    test();
    

    Check working example at http://jsfiddle.net/ewsQ7/5/

提交回复
热议问题