• jQuery Effects-Fading

    jQuery Effects-Fading

    In jQuery Effects-Fading, we can fade an element in and out of visibility. jQuery has the following fade methods:

    1. fadeIn()
    2. fadeout()
    3. fadeToggle()
    4. fadeTo()

    jQuery fadeIn() Method

    The jQuery fadeIn() method is used to make visible a hidden element with animation effect.

    Syntax:   $(selector).fadeIn(speed, callback);

    speed Parameter specifies the duration of the effect. It can take the following values: “slow”, “fast”, or milliseconds.
    callback Parameter is the name of a function to be executed after the fading completes.

    jQuery fadeout() Method

    The jQuery fadeout() method is used to make invisible an element with animation effect.

    Syntax:   $(selector).fadeOut(speed, callback);

    speed Parameter specifies the duration of the effect. It can take the following values: “slow”, “fast”, or milliseconds.
    callback Parameter is the name of a function to be executed after the fading completes.

    jQuery fadeToggle() Method

    The jQuery 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.

    Syntax:   $(selector).fadeToggle(speed, callback);

    speed Parameter specifies the duration of the effect. It can take the following values: “slow”, “fast”, or milliseconds.
    callback Parameter is the name of a function to be executed after the fading completes.

    jQuery fadeTo() Method

    The jQuery fadeTo() method allows fading to a given opacity (value between 0 and 1).

    Syntax:   $(selector).fadeTo(speed, opacity, callback);

    speed

    Parameter specifies the duration of the effect. It can take the following values: “slow”, “fast”, or milliseconds.

    opacity Parameter in the fadeTo() method specifies fading to a given opacity (value between 0 and 1).
    callback Parameter is the name of a function to be executed after the fading completes.

    jQuery Effect-FadeIn/FadeOut Program Code

    Example:

    I have created very simple example to understand FadeIn/FadeOut animation effect on Image using jQuery in program.

    jQuery Effect - FadeIn/FadeOut

    jQuery Effect – FadeIn/FadeOut

    1. First create the New PHP Project in Netbeans.
    1. Add the jQuery libraries. Also add this libraries to your web page.

    <!–Include jQuery Library–>
    <script src=”js/jquery-1.11.3.min.js”></script>

    1. Now start to draw the design structure which is having an Image Control and a button to apply effect. Code written below.

    <body>
    <form name=”frmFadeEffect” id=”frmFadeEffect” method=”post” action=””>
    <div name=”divImage1″ id=”divImage1″>
    <img name=”Image1″ id=”Image1″ src=”images/GaneshLogo4.png” width=”500″ height=”100″ />
    </div>
    <input type=”submit” id=”btnFade” name=”btnFade” value=”FadeOut” />
    </form>
    </body>

    1. Write jQuery code for, when submit button is clicked Image has Fade-Out and submit button value has changed to “FadeIn”. Again submit is clicked image has Fade-In and submit button value has changed to “FadeOut”.

    Note: Here, Submit button click has not recognized by the jQuery code. So, form submit event is used to perform fading operation.

    <!–jQuery Code to FadeIn/FadeOut Image–>
    <script>
    $(document).ready(function(){
    $(“form”).submit(function(event){

    event.preventDefault();
    if($(“#btnFade”).val()==”FadeOut”){

    $(“#divImage1”).fadeOut(3000);
    $(“#btnFade”).val(“FadeIn”);
    }
    else{
    $(“#divImage1”).fadeIn(3000);
    $(“#btnFade”).val(“FadeOut”);
    }
    });
    });

    </script>

    1. Now save and run the practical.
    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *