jquery - Javascript mutiple onClick() functions can run at once when need only 1 at a time -


presently, have few video links on site that, when user clicks them, coorisponding video displayed fadein , fadeout animation. if user happens click on say... video 1 , clicks video 2 before animation completes, displays 2 videos when should display 1. how keep javascript running multiple functions @ once?

code:

$(function(){  var animereviewslink = $('#anime-reviews-link'); var animereviews = $('#anime-reviews'); var animereviewstext = $('#anime-reviews-text'); var animecommentslink = $('#anime-comments-link'); var animecomments = $('#anime-comments'); var animecommentstext = $('#anime-comments-text'); var animeimageslink = $('#anime-images-link'); var animeimages = $('#anime-images'); var animeimagestext = $('#anime-images-text'); var animevideoslink = $('#anime-videos-link'); var animevideos = $('#anime-videos'); var animevideostext = $('#anime-videos-text');  var active1 = animereviewslink; var active2 = animereviews; var active3 = animereviewstext;  animereviewslink.click(function(e) {     active3.hide();     active1.show();     animereviewslink.hide();     animereviewstext.show();     active2.slideup(400);     animereviews.slidedown(400);     active1 = animereviewslink;     active2 = animereviews;     active3 = animereviewstext;     settimeout(function(){},500); });  animecommentslink.click(function(e) {     active3.hide();     active1.show();     animecommentslink.hide();     animecommentstext.show();     active2.slideup(400);     animecomments.slidedown(400);     active1 = animecommentslink;     active2 = animecomments;     active3 = animecommentstext;     settimeout(function(){},500); });  animeimageslink.click(function(e) {     active3.hide();     active1.show();     animeimageslink.hide();     animeimagestext.show();     active2.slideup(400);     animeimages.slidedown(400);     active1 = animeimageslink;     active2 = animeimages;     active3 = animeimagestext;     settimeout(function(){},500); });  animevideoslink.click(function(e) {     active3.hide();     active1.show();     animevideoslink.hide();     animevideostext.show();     active2.slideup(400);     animevideos.slidedown(400);     active1 = animevideoslink;     active2 = animevideos;     active3 = animevideostext;     settimeout(function(){},500); }); }); 

i have tried using settimeout @ end of each function seems doesn't prevent running multiple functions @ same time.

edit: fiddle example - http://jsfiddle.net/vcvpu22q/

thanks.

what this? (edited)

$(function(){ var button1 = $('#button1'); var button2 = $('#button2'); var button1text = $('#button1text'); var button2text = $('#button2text'); var button1click = $('#button1click'); var button2click = $('#button2click');     var canclickbutton = true;  button1.click(function(e){     if(!canclickbutton){return;}      canclickbutton = false;     button2text.hide();     button2.show();     button1.hide();     button1text.show();     button2click.fadeout(500,function(){button1click.fadein(500)});      settimeout(function(){canclickbutton = true;}, 1000);  });  button2.click(function(e){     if(!canclickbutton){return;}      canclickbutton = false;     button1text.hide();     button1.show();     button2.hide();     button2text.show();     button1click.fadeout(500, function(){ button2click.fadein(500) } );      settimeout(function(){canclickbutton = true; }, 1000);  }); 

});


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -