Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add an opacity fading effect to to the jquery slidetoggle?

Tags:

jquery

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?

like image 693
alexchenco Avatar asked Oct 06 '11 09:10

alexchenco


People also ask

What is value of opacity parameter in FADE TO () method?

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.

Can you fade an element to a desired value of opacity using jquery?

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.

What is fade in Javascript?

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.


1 Answers

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.

like image 166
Frédéric Hamidi Avatar answered Sep 22 '22 18:09

Frédéric Hamidi