BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

jQuery fadeIn() Effect

Last Updated: April 24, 2019 by Chaitanya Singh | Filed Under: jQuery

jQuery fadein() effect is used to make an html element appear gradually on the screen. This method also accepts speed and callback function as optional parameters that can help us adjust the fade in speed and run a callback function when the fadein effect is complete.

jQuery fadeIn() syntax

selector.fadeIn( speed, [callback] );

selector: It is used to select a single or multiple html elements on which this fade in effect can be applied. To read more about selectors refer this guide: Selectors in jQuery.

speed: The speed is an optional parameter, fade in speed in milliseconds or in values such as “slow” or “fast”.

callback: callback function that executes when the fadein effect is complete. It is an optional parameter.

jQuery fadeIn() Example

In the following example we have one paragraph and we have set the display to none for this paragraph. On the button click event, we are fading in this paragraph using fadeIn() method.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").fadeIn();
  });
});
</script>
</head>
<body>

<h2>jQuery fadein effect example</h2>
<p style="display:none;">This tutorial is published on beginnersbook.com. This
paragraph will appear when the FadeIn button is clicked.</p>
<button>FadeIn</button>
</body>
</html>

Output:
Before FadeIn button is clicked:
jQuery fadeIn effect
After FadeIn button is clicked:
jQuery fadeIn() effect example

jQuery fadeIn() Example with speed parameter

As mentioned in the fadeIn() syntax, we can pass the speed for fadein effect in milliseconds. Alternatively we are allowed to pass string values such as “slow” and “fast” for slow and fast fading in effects.

$(document).ready(function(){
  $("button").click(function(){
    $("p").fadeIn(2000);
  });
});

jQuery fadeIn() Example with callback function parameter

In the callback function we are passing an alert message when the fadein effect is complete. We have taken the same example that we have seen above. We have just changed the script part in the example.

$(document).ready(function(){
  $("button").click(function(){
    $("p").fadeIn("slow", function(){
      alert("The paragraph is now visible");
    });
  });
});

Output: The output screen looks like this when the fadein effect is complete.
jQuery fadeIn effect speed callback parameters example

❮ PreviousNext ❯

Top Related Articles:

  1. jQuery html() method
  2. jQuery – Chaining multiple effects
  3. jQuery toggle() Effect
  4. jQuery fadeOut() Effect
  5. jQuery Effects – Show and Hide

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

jQuery Tutorial

  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events

jQuery Effects

  • jQuery Show & Hide
  • jQuery Fading
  • jQuery Sliding
  • jQuery Animate
  • jQuery stop()
  • jQuery Callback Function
  • jQuery Chaining

jQuery HTML/CSS

  • jQuery html()
  • jQuery addClass()
  • jQuery hasClass()
  • jQuery removeClass()
  • jQuery toggleClass()
  • jQuery after()
  • jQuery before()
  • jQuery append()
  • jQuery appendTo()
  • jQuery clone()
  • jQuery insertBefore()
  • jQuery insertAfter()
  • jQuery attr()
  • jQuery text()
  • jQuery val()
  • jQuery css()
  • jQuery prepend()
  • jQuery remove()
  • jQuery empty()
  • jQuery detach()

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap