Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want take this code (hover) whit slowly.
(The Jquery code happend whit slowly.)
XML
<head>
    <title></title>
    <script src="jquery.js" type="text/javascript"></script>
    <style>
        #d1
        {
            height: 200px;
            width: 300px;
            position: relative;
            background-color: Red;
            z-index: 3;
        }
        #d2
        {
            height: 50px;
            width: 50px;
            position: relative;
            background-color: green;
            top: 0px;
            left: 35px;
            z-index: 5;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#d2").hide();
        });

        $(document).ready(function () {

            $("#d1").hover(function () {
                $("#d2").show();
                $("#d2").css("color", "yellow");
                for (var i = 1; i <= 100; i++) {
                    var j = (-1) * i;
                    $("#d2").css("background-color", "yellow");
                    $("#d2").css("top", j.toString() + "px");
                }
            },
              function () {
                  $("#d2").hide();
                  $("#d2").css("top", "0px");
                  $("#d2").css("background-color", "green");
              });

        });
    </script>
</head>
<body>
    <div style="background-color: Orange; width: 500px;">
        <div id="d1">
        </div>
        <div id="d2">
            test
        </div>
    </div>
</body>
</html>
Posted
Comments
Sergey Alexandrovich Kryukov 13-Mar-14 17:10pm    
"whit slowly"? What is that supposed to mean? Animation?
—SA

1 solution

Probably you want to animate your handlers changing the look of your elements via CSS. There are different ways to use it; I would advise using jQuery UI library which makes it pretty simple, and use appropriate .addClass() and .removeClass() functions, instead of .css():
http://api.jqueryui.com/addclass[^],
http://api.jqueryui.com/removeclass[^].

Note that you can specify duration, which will define how slowly the styles will be changed during the animation.

Another approach which can potentially give more flexibility is explicit use of .animate() and .stop():
http://api.jquery.com/stop[^],
http://api.jquery.com/animate[^].

This is some code sample: http://stackoverflow.com/questions/7302824/animating-addclass-removeclass-with-jquery[^].

See also: http://api.jquery.com/category/effects[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900