• jQuery Effect-Sliding

    jQuery Effect-Sliding

    In jQuery Effect-Sliding, slides elements up and down. jQuery has the following slide methods:

    • slideDown()
    • slideUp()
    • slideToggle()

    jQuery slideDown() Method

    The jQuery slideDown() method is used to slide down an element.

    Syntax:   $(selector).slidedown(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 slideUp() Method

    The jQuery slideUp() method is used to slide up an element.

    Syntax:   $(selector).slideUp(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 slideToggle() Method

    The jQuery slideToggle() method toggles between the slideDown() and slideUp() methods. If the elements are slide down, slideToggle() will slide them up. If the elements are slide up, slideToggle() will slide them down.

    Syntax:   $(selector).slideToggle(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 Slide Up/Down Program Code

    Example:

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

    JQuery Effect-SlideUp/Down

    JQuery Effect-SlideUp/Down

    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=””>

    <table>
    <tr>
    <th colspan=”2″>Slide Effect – SlideUp/SlideDown</th>
    </tr>
    <tr>
    <td>
    <div name=”divImage1″ id=”divImage1″  width=”500″ height=”100″>
    <img name=”Image1″ id=”Image1″ src=”images/GaneshLogo4.png” width=”500″ height=”100″ />
    </div>
    </td>
    </tr>
    <tr>
    <td style=”text-align: center;”>
    <input type=”submit” id=”btnSlide” name=”btnSlide” value=”SlideUp” />
    </td>
    </tr>
    </table>
    </form>
    </body>

    1. Write jQuery code for, when submit button is clicked Image has Slide-Up and submit button value has changed to “SlideDown”. Again submit is clicked image has Slide-Down and submit button value has changed to “SlideUp”.

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

    <!–jQuery Code to SlideUp/SlideDown Image–>
    <script>
    $(document).ready(function(){
    $(“form”).submit(function(event){
    event.preventDefault();
    if($(“#btnSlide”).val()==”SlideUp”){
    $(“#Image1”).slideUp(3000);
    $(“#btnSlide”).val(“SlideDown”);
    }
    else{
    $(“#Image1”).slideDown(3000);
    $(“#btnSlide”).val(“SlideUp”);
    }

    });
    });
    </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 *