jquery visibility effects

jQuery Visibility Effects

jQuery is a popular JavaScript library that simplifies the process of manipulating HTML documents. One of its useful features is the ability to control the visibility of HTML elements through animation effects. Here are some common methods to achieve this:

fadeIn() and fadeOut() methods

The fadeIn() and fadeOut() methods are used to gradually show or hide an element. They take an optional parameter for the duration of the animation in milliseconds, and an optional parameter for a callback function to be executed after the animation completes. Here's an example:


$(document).ready(function(){
    $("button").click(function(){
        $("p").fadeOut(1000);
    });
});

In this example, a button is selected using the $() function, and when it is clicked, the <p> element is faded out over a 1-second period.

slideDown() and slideUp() methods

The slideDown() and slideUp() methods are used to show or hide an element by sliding it up or down. They also take optional parameters for duration and callback functions. Here's an example:


$(document).ready(function(){
    $("button").click(function(){
        $("p").slideUp(1000);
    });
});

This example selects a button and when it is clicked, the <p> element slides up over a 1-second period.

show() and hide() methods

The show() and hide() methods simply show or hide an element, without any animation effect. They also take optional parameters for duration and callback functions. Here's an example:


$(document).ready(function(){
    $("button").click(function(){
        $("p").hide(1000);
    });
});

In this example, a button is selected and when it is clicked, the <p> element is hidden over a 1-second period.

Overall, these methods are useful for creating dynamic and interactive effects on web pages using jQuery.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe