I want to have two buttons, one to fade div1 out, and one either to fade div1 in, or to fade out the button itself, if the div1 is already hidden. here's the code, pretty unnecessary though, cause my main problem is "if" statement...
$('#b > button').click(function(){
$('#div1').fadeOut(400)
});
$('#div2 > button').click(function(){
$('#div1').fadeIn(400)
});
Definition and Usage. The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out.
The jQuery fadeIn() method is used to fade in a hidden element. Syntax: $(selector).fadeIn(speed,callback);
jQuery fadeOut() Effect Example with speed parameter ready(function(){ $("button"). click(function(){ $("p"). fadeOut(2500); }); }); Or you can specify the speed as “slow” or “fast” as shown below.
fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none , so the element no longer affects the layout of the page. Durations are given in milliseconds; higher values indicate slower animations, not faster ones.
FadeOut simply changes the display
to none
.
Check if the display is none using jQuery's $('selector').css('display')
or $('selector').is(':visible')
Why not to disable/enable the buttons?
$('#b > button').click(function(){
$('#div1').fadeOut(400, function() {
$(this).prop('disabled', true);
$('#div2 > button').prop('disabled', false);
});
});
$('#div2 > button').click(function(){
$('#div1').fadeIn(400, function() {
$(this).prop('disabled', true);
$('#b > button').prop('disabled', false);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With