below is jQuery code I have used for cycling advert banner. For some reason the background colour is changing before each image fades out, despite having it the other way around in the code? Does anybody know where I might be going wrong here? Thanks. The '#contentHome' Div is a parent DIV for the cycling adverts inside (the adverts with class .advertSlide). The parent DIV is wider at 100% width and adverts inside have a fixed width. One advert has blue background '#103663" and the other black "#000000". The code aims to change the parent div background colour at each image change.
I'd like to achieve this order:
- current advert to fade out on it's own background colour (bg colour assigned to the parent DIV: contentHome)
- Then the background colour and/or background image changes
- Then next advert div (with image) fades in.
essentially: FadeOut > bg change > FadeIn
At the moment it goes:
- Background colour changes (so doesn't match advert)
- Then advert fades out.
- Then next advert fades in?
so...wrongly doing: bg Change > FadeOut > FadeIn.
Here is my code:
sliderInt = 1;
sliderNext = 2;
$(document).ready(function() {
$("#slider > div#myDIV1.advertSlide").fadeIn(1000);
startSlider();
});
function startSlider() {
count = $("#slider > div.advertSlide").size();
loop = setInterval(function(){
if(sliderNext > count) {
sliderNext = 1;
sliderInt = 1;
}
if(sliderNext == 2) {
$("#slider > div.advertSlide").fadeOut(1000).delay(500);
$("#contentHome").delay(2000).css("background-image", "url(images/ssBackground2px.png)").css("background-repeat", "repeat").css("background-color","#103663");
}
if(sliderNext == 1) {
$("#slider > div.advertSlide").fadeOut(1000).delay(500);
$("#contentHome").delay(2000).css("background-image", "none").css("background-color", "#000000");
}
$("#slider > div#myDIV" + sliderNext + ".advertSlide").delay(500).fadeIn(1000);
sliderInt = sliderNext;
sliderNext = sliderNext + 1;
}, 10000)
Thanks in advance for any help you can give.