jQuery Fadetoggle Function Example

Let's have a closer look at the jQuery .fadetoggle() function.

Demo Code Download

Description

The same as .slideToggle() but with a fading effect. The .fadeToggle() uses the popular .fadeIn() and .fadeOut() events to show and hide content on a web page. Lets have a look at an example of the fadetoggle jQuery function in action. Further Reading »

Demo

jQuery Function Demo - jQuery4u.com

Demo: Fade an element in and out of view. Click "Run Demo" to activate fade in/out.

Run Demo View Code


Download

The download package includes all the inline HTML, CSS, JavaScript, jQuery and images required for the .fadetoggle() function demo so you can try it yourself and change as you please.

The full code listing for all jQuery functions have been now added to GitHub, you can get them there, we are making them work with the latest versions of jQuery!

Code

<!-- Copyright 2011 jQuery4u.com -->
<!DOCTYPE html>
<html>
<title>jQuery Function Demo - jQuery4u.com</title>
<head>
    <script src="http://www.jquery4u.com/function-demos/js/jquery-1.6.4.min.js"></script>
    <script src="http://www.jquery4u.com/scripts/function-demos-script.js"></script>

    <script type="text/javascript">

    var JQFUNCS =
    {
        runFunc:
        {
            /* ------------------------------ fadeToggle Demo ------------------------------ */
            "fadetoggle":
            {
                run: function(id)
                {
                    $('.readmore').fadeToggle('slow');
                },

                reset: function(id)
                {}
            }
        }
    }

    </script>

</head>
<body>

<p class="example">Demo: Fade an element in and out of view. Click "Run Demo" to activate fade in/out.</p>
<p><a href="#" id="fadetoggle-demobtn" class="demobtn btn actionr">Run Demo</a> <a href="#" id="fadetoggle-codebtn" class="codebtn btn actionr">View Code</a></p>
<div class="demoarea" id="fadetoggle"><div class="readmore" style="display:none">Curabitur placerat commodo augue eget congue. Aliquam id ante leo. Duis at libero magna, at dignissim odio. Aliquam aliquet suscipit mollis. Pellentesque libero tortor, elementum id mattis vel, mattis eget metus. Nam convallis interdum imperdiet. Fusce at magna tellus. Sed mi ante, aliquam at accumsan ac, tristique sit amet dui. Aliquam eleifend molestie ligula. Vivamus eleifend, diam id tincidunt posuere, ipsum dui elementum sapien, posuere pulvinar risus neque id turpis. Nullam volutpat cursus libero, sit amet euismod justo eleifend vitae.</div></div>

</body>
</html>
<!-- Copyright 2011 jQuery4u.com -->