jQuery class transition animation

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.11.2.js"></script>
    <script src="jquery-ui.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var applyClass = true;
            $('#btnAnimate').click(function () {
                if (applyClass) {
                    $('#myDiv').addClass('redDiv', 2000);
                }
                else {
                    $('#myDiv').removeClass('redDiv', 2000);
                }
                applyClass = !applyClass;
            });
        });
    </script>
    <style>
        .redDiv {
            background-color: red;
            color: white;
            font-size: 20px;
            border: 5px solid black;
            padding: 5px;
            width: 500px;
        }
    </style>
</head>
<body style="font-family: Arial">
    <form id="form1" runat="server">
        <div id="myDiv">
            At Pragim Technologies, training is delivered by real time software experts
            having more than 10 years of experience. Interview questions and real time
            scenarios discussion on topics covered for the day. Realtime projects
            discussion relating to the possible interview questions. Trainees can attend
            training and use lab untill you get a job. Resume preperation and mock up
            interviews. 100% placement assistance. 24 hours lab facility.
        </div>
        <br />
        <input type="button" id="btnAnimate" value="Animate" />
    </form>
</body>
</html>

toggleClass() example : Modify the code in jQuery ready function to use toggleClass() instead of addClass() and removeClass() methods.

$(document).ready(function () {
    $('#btnAnimate').click(function () {
        $('#myDiv').toggleClass('redDiv', 2000);
    });
});

Comments

Popular posts from this blog

Drag and Drop multiple File upload using jQuery AJAX in ASP.Net using C# and VB.Net

jQuery dynamic menu from database in asp.net

Automatically send Birthday email using C#.Net