jqueryhtmlcssfadeindefinite

Changing background image div


I would like to design a page on which the back ground image changes in a round-robin fashion, indefinitely. Now I have something that works but only if there's no other <div>s on that page as it loops through all the divs. Now I want to add content in other divs so I need to edit that jQuery somehow to only loop through the divs with "backgnd" in their class name. How do I do this? My example link: http://jsfiddle.net/bbqunfhu/26/ function to edit:

function fadeDivs() {
var visibleDiv = $('.bckgnd:visible:first'); //find first visible div
visibleDiv.fadeOut(400, function () {  //fade out first visible div
   var allDivs = visibleDiv.parent().children(); //all divs to fade out / in
   var nextDivIndex = (allDivs.index(visibleDiv) + 1) % allDivs.length;  //index of next div that comes after visible div
   var nextdiv = allDivs.eq(nextDivIndex); //find the next visible div
   nextdiv.fadeIn(400); //fade it in
});
};

Solution

  • i have changed to search only children with class '.bckgnd'.

    var allDivs = visibleDiv.parent().children('.bckgnd'); //all divs to fade out / in
    

    here