PDA

View Full Version : Resolved JQuery Delay in adding and removing classes.



Deadweight
10-14-2013, 03:51 PM
Hello, Im using jquery to add and remove classes. However, i want it to delay the removal or addition of the class. Here is my query:


$('div.dropper').click(function(){
if($(this).children('.sub_title').hasClass('closed')){
$(this).children('.sub_title').removeClass('closed').addClass('opened');
$(this).children('.content').slideDown(300);
}else{
$(this).children('.content').slideUp(300);
$(this).children('.sub_title').delay(300).addClass('closed').removeClass('opened');

}
});

What I'm trying to do is when the content finishes scrolling up then i want the class to change.

Any ideas? Thanks

Deadweight
10-14-2013, 04:04 PM
Actually i figured it out and ill post it here to show you my solution:

$('div.dropper').click(function(){
if($(this).children('.sub_title').hasClass('closed')){
$(this).children('.sub_title').removeClass('closed').addClass('opened');
$(this).children('.content').slideDown(300);
}else{
$(this).children('.content').slideUp(300);

$(this).children('.sub_title').delay(300).queue(function(reset_delay){
$(this).addClass('closed').removeClass('opened');
reset_delay();
});



}
});