jQuery Tutorial #04 Effects Part 01 ( Show, Hide, Toggle, FadeIn, FadeOut and FadeToggle)

Image Source

Repository

https://github.com/jquery/jquery 

What Will I Learn?

I will learn the jQuery effects part 01 the show, hide, toggle, fadeIn, fadeout and fadetoggle effects with examples.

  • What's the Show/Hide effects and how to use them.
  • The definition of FadeIn/FadeOut effects and their uses.
  • Combine between Show/Hide by Toggle Effect.
  • Combine between FadeIn/FadeOut by FadeToggle Effect.

Requirements

  • Knowledge about HTML5 and CSS3
  • Knowledge about jQuery
  • A text editor like notpad ++ 

Difficulty

  • Basic

Description

In this tutorial we will take the jquery effects part 1 , in this part we will take the Show, Hide, Toggle, FadeIn, FadeOut and FadeToggle effects with examples . 

1-Show Effect :

Is a method sets the display proprieties of elements to whatever they initially were they block, inline, or inline-block before the inline style display: none was applied to them.

To use the show effect we must select the element then apply the show() method

$('element').show(speed, function () { // something here });

In this example when the user clicks on ' Advanced Search ' button, the system will display the advanced search div by using ' show ' effect.

2-Hide Effect :

The hide() method simply change the inline style display: none for the selected elements.

To use the hide effect we must select the element then apply the hide() method  

$('element').hide(speed, function () { // something here });

In the same example if the user wants to return to the default search or the simple search, he will click on the button ' Simple Search ' and the system will hide the advanced search and show the simple search.

My code : 

/***** Show and Hide Effects *****/

    $('.advancedSearch').click(function () {

        $(this).toggleClass('activeButton');

        if ($(this).hasClass('activeButton')) {

            $('.searchAdv').show(1000);

            $(this).html('Simple Search')

            $('.inputSearchA').hide(1000);

        } else {

            $('.searchAdv').hide(1000);

            $(this).html('Advanced Search');

            $('.inputSearchA').show(1000);

        }

    });

The show method will set the display propriety to ' block , inline or inline-block ' depend on the default propriety , the hide method will set the display propriety to ' none ' to hide the element.

3- Toggle Effect :

The toggle() method show or hide the elements, if the element is initially displayed, it will be hidden; if hidden, it will be displayed.

To use the toggle effect we must select the element then apply the toggle() method  $('element').toggle(speed, function () { // something here });

I will use the same example by toggle effect, I will display and hide the advanced search div with the click event.

My Code :

/****** Toggle Effect ******/

    $('.advancedSearch').click(function () {

        $('.searchAdv').toggle(1000);

        $('.inputSearchA').toggle(1000);

        if ($('.searchAdv').css('display') === 'block') {

            $('.advancedSearch').html('Simple Search');

        } else {

            $('.advancedSearch').html('Advanced Search');

        }

    });

The first input with class ' inputSearchA ' has the display inline propriety, by the toggle effect it will be hidden , the display propriety will be ' hide ' .

The advanced search is hidden, by the toggle effect it will be shown , the display propriety will be ' block '.

4- FadeIn Effect :  

The fadeIn function of the Jquery framework makes it possible to display an element or set of html elements that are invisible to the user. It will give a progression effect by modifying the opacity when displaying this element.

To use the fadeIn effect we must select the element then apply the fadeIn() method  $('element').fadeIn(speed, function () { // something here });

I will show a list of items when I pass the mouse on the service item using the mouseenter event, this effect will change the opacity of element from 0 to 1 to become more smooth.

My code:

$('.service').mouseenter(function () {

        $('.secondList').fadeIn(1000);

        $(this).addClass('active');

 });

When I pass the mouse on the service item , I will show the second list by fadeIn effect and add the active class or the green background to the service item and this is the result 

5- FadeOut Effect :

The fadeOut function of the Jquery framework makes it possible to remove an element or a set of html elements by making them invisible to the user. It will give a progression effect by modifying the opacity at the disappearance of this element.

To use the fadeOut effect we must select the element then apply the fadeOut() method  $('element').fadeOut(speed, function () { // something here });

When I leave from the service item the system will hide the second list using the fadeOut method.

My Code :

$('.service').mouseleave(function () {

        $('.secondList').fadeOut(10000);

        $(this).removeClass('active');

});

The fadeout method will change the opacity of the second list from 1 to 0 to be hidden, I also removed the active class from the element to be with the transparent background and this is the result 

6- FadeToggle Effect :

The jQuery fadeToggle() method display or hide the selected elements by animating their opacity in such a way that if the element is initially displayed, it will be fade out; if hidden, it will be fade in.

To use the fadeToggle effect we must select the element then apply the fadeToggle() method  $('element').fadeToggle(speed, function () { // something here });

I will use the same example but with the click event , when I click on the button the system will test if the value of display propriety is ' none ' it will fadeIn the element else it will fadeOut it will change the opacity from 0 to 1 and from 1 to 0.

My Code :

$('.service').click(function () {

        $('.secondList').fadeToggle(10000, function () {

            console.log('toggle');

        });

    });

You can do something when the operation finished and this is the callback function.

Video Tutorial 

Sort:  

Hi @alexandre-maxim,

Thank you for your contribution.

I see that you put effort to improve on your video tutorial each time. The video tutorial seems more structured but there needs more improvement in the delivery of the tutorial.

  • Try to section your tutorial in such a way that learners can clearly see when a new step is shown for the concept. In that way, your tutorial will not be 'run-on' with continuous rambling.

  • In your delivery speech, let the outline to become more distinct as you signal your learners of applying new steps.

  • Try to make some fonts larger as the smaller fonts tend to be blurry and hard on the eyes

Finally, there are many basic concepts that are taught on the internet regarding this subject. If you continue to teach basic concepts, you need to show where your video tutorial is unique so that learners will choose to follow to learn from your series.

I look forward to your next contribution.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your encouragement @rosatravels, I will try to show the steps well, but for the basic concepts I am trying to present examples and ideas that exist in real websites to understand the use of these functions , I will present distinct things in the future , Thank you again.

Thank you for your review, @rosatravels!

So far this week you've reviewed 2 contributions. Keep up the good work!

Hi @alexendre-maxim! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test modus upvoting quality Utopian-io contributions! Nice work!

Hey @alexendre-maxim
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @alexendre-maxim! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62978.31
ETH 2546.24
USDT 1.00
SBD 2.76