(Javascript/jQuery新手)
我正在练习将所有的Javascript放到一个单独的.js文件中(这是一个小型的个人网站),并尝试在特定的body#div存在时激发特定的函数。(我基于代码
One JS File for Multiple Pages
,但可能有更好的方法来写。)
由于某种原因(可能是在尝试访问另一个#home1时),动画将无法运行。我可以在动画之前调用一个警报,但实际的动画函数有问题。
提前感谢。
HTML格式:
<script type="text/javascript" src="javascript/jquery-1.11.1.js"></script>
<script type="text/javascript" src="javascript/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="javascript/script.js"></script>
<link href="css/hover/css/hover.css" rel="stylesheet" media="all">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body id="home">
<div class="container">
<p>Website content here</p>
</div>
<div class="footer">
<div id="home1"></div>
<div id="home2"></div>
</div>
</body>
CSS:
#home1 {
position: relative;
top: -400px;
margin-left: auto;
margin-right: auto;
width: 40px;
height: 40px;
background-color: yellow;
}
JS文件:
$(document).ready(function() {
if ($("body#home").length > 0) {
//alert("dhd");
$("#home1").animate({
top: '0px';
}, 1000, 'easeOutBounce');
}
});