Change the body background image with fade effect in jquery

后端 未结 7 1648
说谎
说谎 2020-12-01 09:40

Hey i want to fade in a new background image let´s say every 60 seconds. I´ve set the background image like this:

body {background-image: url(background.jpg)         


        
7条回答
  •  無奈伤痛
    2020-12-01 10:15

    jQuery(document).ready(function() {
    var cnt=0, bg;
    var $body = jQuery('body');
    var arr = ['secondbg.jpg','sartulebis-archeva2.png'];
    
    animate = function(){
    
    }
    var bgrotater = setInterval(function() {
        if (cnt==2) cnt=0;
        bg = 'url("http://yalcingroup.ge/test/wp-content/uploads/2015/08/' + arr[cnt] + '")';
        cnt++;
        jQuery('#background_cycler').animate({opacity:1}, 2000, function(){
            $body.css('background-image', bg);
        });
    
    
        jQuery('#background_cycler').animate({opacity:0}, 2000);
    },10000);
    

    });

提交回复
热议问题