I've made a slideshow using jQuery. It uses the fadeIn and fadeOut methods. This works fine.
What I need help with is adding a css class to another div, depending on which slide is shown. I've added some shortened code to JSfiddle so you can get a better idea what I mean.
I want the pink boxes to become highlighted when the corresponding slide is shown.
Adding the following, doesn't seem to work:
if ($("#firstSlide").css("display") == "block") {
$("#div1").addClass("Highlight");
$("#div2").removeClass("Highlight");
$("#div3").removeClass("Highlight");
}
Three major problems:
.Highlight
is the same as .button
and because .Highlight
comes first in the CSS definition, the bg color from .button
is winning out and keeping it pink. Give it higher specificity or higher importance (e.g. div.Highlight
or .button.Highlight
or use !important
)if
looked ok but the other two condition blocks were wrong. I'm going to assume that was just a demo typo. But I fixed it in my example.http://jsfiddle.net/dRqKM/1/ See this fiddle for a working version. Note that if you want the box to turn BEFORE the fade ends, just move the call to changeActiveChild
to be after the fadeIn
call instead of inside the callback function, e.g. http://jsfiddle.net/dRqKM/6/