I'm using the following code to slide up and down a div:
$(document).ready(function(){
$(".toggle-button").click(function () {
$(".about").slideToggle("slow");
});
});
I will like to add a fade in and fade out effect to the toggle button. Any suggestions about how to do that?
The required opacity parameter in the fadeTo() method specifies fading to a given opacity (value between 0 and 1). The optional callback parameter is a function to be executed after the function completes.
The . fadeTo() method animates the opacity of the matched elements. It is similar to the . fadeIn() method but that method unhides the element and always fades to 100% opacity.
The fade effect is described as the gradual increase and decrease in the opacity of the selected portion. In other words, the fade effect is termed as the increase and decrease in opacity with respect to time. When this effect is applied with a gradual increase in the opacity it is known as the fade-in effect.
A simple way to achieve this is to pass the toggle
value to animate():
$(document).ready(function() {
$(".toggle-button").click(function() {
$(".about").animate({
height: "toggle",
opacity: "toggle"
}, "slow");
});
});
You can see the results in this fiddle.
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