Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FadeIn/FadeOut Toggle Using One Button

Tags:

jquery

button

I am currently using this code to try and use a button with a class of .info as a toggle for fading in and fading out text. Right now the animation is running back to back with this code. Is there a way where I click the button once and have the text fade in without it fading out seconds later? The same will apply for fading out when you click the button again.

$('.info').click(function() {
    $('h7').fadeIn(750);
});

$('.info').click(function() {
    $('h7').fadeOut(750);
});         
like image 831
tntran10 Avatar asked Mar 26 '13 16:03

tntran10


People also ask

Which of the following method is used to toggle between the fadeIn () method and fadeOut () method?

The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in.

What is the syntax of jQuery fadeOut () method?

The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector).fadeOut(speed,callback); The optional speed parameter specifies the duration of the effect.

What is the syntax of jQuery fadeToggle () method?

jQuery fadeToggle() If the elements are faded in, it will make them faded out and if they are faded out it will make them faded in. Syntax: $(selector). fadeToggle();

What is the difference between fadeOut and hide in jQuery?

Main difference between FadeIn, FadeOut vs hide, Show is When you use FadeIn and fadeout Its remove line Slowly Like Opacity will 100 to 0 in a few mili-second but On other hand hide, Show will remove the line immediately Without wasting any mili-second.


2 Answers

You can use fadeToggle()

$('.info').click(function() {
    $('h7').fadeToggle(750);
}
like image 184
97ldave Avatar answered Oct 05 '22 02:10

97ldave


$('info').click(function(){
    $('h7').fadeToggle(750);
});
like image 24
Dom Avatar answered Oct 05 '22 01:10

Dom