Div不改变颜色 - jQuery

时间:2015-03-12 00:07:00

标签: javascript jquery css

所以我只是试图让这个div在moused时慢慢改变颜色。我有这个:

<script type="text/javascript">
    $("#down").mouseover(function(){
        $("#down").animate({background: "#a34545"}, 5000)
    });
</script>

不应该那么复杂,虽然我认为我还必须添加一个mouseout功能。我测试了到目前为止我所拥有的,没有任何反应。它只是保持相同的颜色。我错过了什么?

这是HTML:

<!DOCTYPE html>
<html>
<head>
    <title>The Down-Champlain Regatta</title>
    <link rel="stylesheet" href="homepage.css"/>
    <link href='http://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
    <script src="jquery-1.11.2.js"></script>
</head>
<body>
    <div id="topcontainer">
        <img src="Images/Kim.jpg" id="tom">
        <img src="Images/Kim.jpg" id="zach">

        <div id="head">
            <p id="a">Hello South Burlington. We're the</p>
            <h5>Down Champlain Regatta.</h5>
            <p id="s">And we've got a bold new plan for sailing education on Lake Champlain.</p>
        </div>

        <div id="down">
            <p>check it out</p>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            $("#down").mouseover(function(){
                $("#down").animate({backgroundColor: "#a34545"}, 5000)
            });
        });
    </script>
</body>
</html>

我认为可能是我的网络阻止访问jQuery库(学校计算机),所以我下载了库并在头部添加了链接。这对你们好吗?它还没有用......

3 个答案:

答案 0 :(得分:1)

您的代码完美无缺。

请参阅此FIDDLE DEMO

只需要包含jquery UI 1.8.5 这就是jquery的animate函数来自的地方。

请参阅Jquery Animate

   Color Animation
Animate the properties of elements between colors.

另外: $("#down").animate({background : "#a34545"}, 5000);

应该是:  $("#down").animate({backgroundColor : "#a34545"}, 5000);

答案 1 :(得分:0)

你应该在$(document).ready

<script type="text/javascript">
    $(document).ready(function(){
        $("#down").mouseover(function(){
            $("#down").animate({backgroundColor: "#a34545"}, 5000)
        });
    });
</script>

答案 2 :(得分:0)