Monday, June 9, 2014

Implement fade-in/fade-out effect with jQuery

Example to implement fade-in/fade-out effect using jQuery:


<!DOCTYPE html>
<head>
</head>
<body>
    <h1 id="titleh1">Fade-in/Fade-out example</h1>
    <button id="go">Run</button>

    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script>
        $(function(){

            function runFadeOutFadeIn(){

                $("#titleh1").fadeTo(
                    "slow", 0, function(){
                        $("#titleh1").fadeTo(
                            "slow", 1, function(){});
                    });
            }
            
            $("#go").click(
                function(){
                    runFadeOutFadeIn();
                });
        });
    </script>
</body>
</html>

No comments:

Post a Comment