KOSUNI KOREA
Korean News in English
Technology

jQuery Tutorial: Creating Effects and Animations

Published October 16, 2026 · 1 views
jQuery Tutorial: Creating Effects and Animations

What You'll Learn in This Lesson

So far, you've learned how to modify HTML and CSS or handle events.

But to make your website feel more natural and visually appealing, you need various effects and animations.

For example:

  • Menus that smoothly expand

  • Panels that gradually appear

  • Images that slowly fade away

  • Boxes moving when buttons are clicked

  • Banners sliding in and out

jQuery makes creating these effects incredibly simple.


Preparation for Practice

First, create the following HTML:

<button id="btnShow">Show</button>

<button id="btnHide">Hide</button>

<button id="btnToggle">Toggle</button>

<div id="box"></div>

Add this CSS as well:

#box{

    width:200px;

    height:200px;

    background:#4da3ff;

    margin-top:20px;

}


hide()

The most basic effect.

Hides an element.

$("#btnHide").click(function(){

    $("#box").hide();

});

Clicking the button makes the box disappear.


show()

Displays a hidden element again.

$("#btnShow").click(function(){

    $("#box").show();

});

This function is always used alongside hide().


toggle()

Alternates between showing and hiding.

$("#btnToggle").click(function(){

    $("#box").toggle();

});

This is the most commonly used function for menu toggling.


Setting Animation Speed

You can specify animation duration.

$("#box").hide(1000);

1000 means 1000 milliseconds, or 1 second.

Alternatively:

$("#box").hide("slow");

$("#box").show("fast");

You can use these as well.


fadeOut()

The element gradually fades out of view.

$("#box").fadeOut();

This provides a much smoother effect than the standard hide() function.


fadeIn()

Creats a gradual appearance effect.

$("#box").fadeIn();

This is commonly used for pop-up windows or image loading.


fadeToggle()

Alternates between showing and fading away.

$("#box").fadeToggle();


fadeTo()

You can directly set the opacity level.

$("#box").fadeTo(1000,0.3);

This means:

  • Change over 1 second

  • To 30% opacity

is requested.


slideUp()

The element slides up and disappears.

$("#box").slideUp();

This function is most commonly used in accordion menus.


slideDown()

The collapsed element expands.

$("#box").slideDown();


slideToggle()

Alternates between opening and closing.

$("#box").slideToggle();

This is one of the most frequently used functions in real-world development.


animate()

The function for creating custom animations.

For example, let's move the box to the right:

$("#box").animate({

    left:"300px"

});

Note that for animate() to work, the element must have:

position:relative;

defined.


Changing Multiple Properties Simultaneously

$("#box").animate({

    left:"300px",

    width:"300px",

    height:"300px",

    opacity:0.5

},1000);

Over 1 second, the following will happen simultaneously:

  • Movement

  • Size change

  • Opacity adjustment

is executed.


Chaining Multiple Animations

$("#box")

.animate({

    left:"300px"

})

.animate({

    top:"150px"

})

.animate({

    left:"0px"

})

.animate({

    top:"0px"

});

The animations will run in sequence.

This is also used in game development and banner creation.


stop()

Stops an animation immediately.

$("#box").stop();

This prevents animations from stacking when hovering over and away repeatedly, which is common in real-world scenarios. It's almost always used alongside other animation functions.


delay()

Pauses before executing the next animation.

$("#box")

.fadeOut()

.delay(1000)

.fadeIn();

The element will reappear after a 1-second delay.


Real-World Example 1

Menu Toggling

$("#menuBtn").click(function(){

    $("#menu").slideToggle();

});

This is the most common method for mobile menus.


Real-World Example 2

Notice Popup

$("#popup").fadeIn();

Close button:

$("#close").click(function(){

    $("#popup").fadeOut();

});


Real-World Example 3

Image Zoom Effect

$("#photo").mouseenter(function(){

    $(this).stop().animate({

        width:"350px"

    });

});

$("#photo").mouseleave(function(){

    $(this).stop().animate({

        width:"250px"

    });

});

This is a common feature on e-commerce sites.


Real-World Example 4

Button Shake Effect

$("#btn")

.animate({

    left:"10px"

},100)

.animate({

    left:"-10px"

},100)

.animate({

    left:"0px"

},100);

This effect is frequently used for login failures or warning messages.


Properties You Can Animate

Animate() can only change properties that are numerical values.

For example:

Allowed:

  • width

  • height

  • left

  • top

  • opacity

  • margin

Not Allowed:

  • background-image

  • display

  • font-family

are not supported.


Common Mistakes for Beginners

Not Specifying Position

This is the main reason why left or top properties don't work.

You must specify either:

position:relative;

or

position:absolute;

for the element.


Forgetting to Use stop()

If you trigger mouseenter multiple times, animations stack up.

In real-world development, it's best to get into the habit of using:

.stop()

alongside your animation functions.


Mixing Up hide() and fadeOut()

hide() makes an element disappear instantly.

fadeOut() fades the element out gradually.

You should choose based on context.


Practice Assignments

Assignment 1

Create a button that makes the box disappear when clicked, and reappear when clicked again.


Assignment 2

Make an image fade away over 2 seconds.


Assignment 3

Create a menu button that opens and closes the menu with a slide effect.


Assignment 4

Use animate() to move the box right by 400px.


Assignment 5

Create a button that moves the box, then increases its size before returning it to its original position.


Key Takeaways

  • hide(), show(), and toggle() control element visibility.

  • Fade-related functions provide opacity-based effects.

  • Slide-related functions create expansion and collapse effects.

  • Animate() allows you to create custom animations.

  • stop() prevents animation stacking.

  • delay() pauses before the next animation runs.

  • Fade, slide, and animate functions are widely used in real-world websites for menus, popups, banners, e-commerce sites, and more.


Conclusion

In this lesson, we explored jQuery's effects and animation capabilities.

Complex screen transitions can be implemented with just a few lines of code in jQuery, providing users with a more natural and intuitive interface.

Especially the fade, slide, and animate functions are frequently used in real-world development, so it's important to practice creating various examples to become familiar with them.

In our next lesson, we'll learn about DOM Navigation and Adding/Removing Elements, where you'll practice finding elements, creating new ones, and deleting existing ones.

FAQ

What is the difference between hide() and fadeOut()?

hide() makes an element disappear instantly while fadeOut() gradually fades it out over time.

Why do I need position:relative for animate()

animate() requires elements to have a positioned parent (relative or absolute) to change left, top, and other positional properties.

Korean Source

This article is an English localization of a Korean-language report from BlogScore. Original: [Jquery 강좌] 5강 효과(Effect)와 애니메이션 만들기