Javascript 如何设置Div的动画?

Javascript 如何设置Div的动画?,javascript,jquery,html,animation,Javascript,Jquery,Html,Animation,有人能不能快速告诉我我做错了什么:这可能是一个非常简单的错误 <!DOCTYPE html> <html> <head> <title>Random Animation Bullshit</title> <link href='http://fonts.googleapis.com/css?family=Cutive+Mono' rel='stylesheet' type='text/css'> <link rel="

有人能不能快速告诉我我做错了什么:这可能是一个非常简单的错误

<!DOCTYPE html>
<html>
<head>
<title>Random Animation Bullshit</title>
<link href='http://fonts.googleapis.com/css?family=Cutive+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="animation.css"/>
</head>
<body>
<div id="moving_header">
    <ul id="menu">
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Products</a></li>
    </ul>

    <h1>DELL Computers</h1>
</div>

<script type="text/javascript">
$(document).ready(function() {
    $("#moving_header").mouseover(function() {
        $("#moving_header").animate({
        margin-top: 0px;
        }, 5000);
    });
});
</script>
</body>
</html>

这是因为jQuery不在您的文件中。以下是添加了jQuery的标题的修改版本:

<head>
<title>Random Animation Bullshit</title>
<link href='http://fonts.googleapis.com/css?family=Cutive+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="animation.css"/>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>

随机动画废话
编辑:改用这个

<head>
<title>Random Animation Bullshit</title>
<link href='http://fonts.googleapis.com/css?family=Cutive+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="animation.css"/>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>

随机动画废话

是否包含jQuery??页面上没有包含jQuery。请去掉
页边空白顶部的分号:0px-另外,我认为这两个都需要是字符串,所以用引号将
边距顶部
0px
都包装起来。代码看起来不错。鼠标悬停前的页边空白是多少?如果为0px,则动画设置为0px时不会发生任何事情;另外,需要“marginTop”而不是marginTop,而“0px”需要引号。你应该使用marginTop:“0px”,而不是marginTop:0pxNope,仍然没有做任何事情。div的初始位置是什么?考虑到初始的margin是0,我正在添加100px。对初始答案进行了更改,意识到我给了你错误的链接,我的错!
<head>
<title>Random Animation Bullshit</title>
<link href='http://fonts.googleapis.com/css?family=Cutive+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="animation.css"/>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>
<head>
<title>Random Animation Bullshit</title>
<link href='http://fonts.googleapis.com/css?family=Cutive+Mono' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="animation.css"/>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>