Jquery .animate不会工作

时间:2013-06-24 07:12:37

标签: jquery html

不知道为什么,但是我拼命想要在jsfiddle上找到jquery淡入淡出的例子来处理我的网站...但是我不能让我的网站工作...在我的头脑中第一页链接到http://code.jquery.com/jquery-1.10.1.min.js然后我链接到文件我有我的js代码(小块)。以下是jsFiddle http://jsfiddle.net/a9dnW/417/

的链接

的jQuery

$("#test p").delay(1000).animate({"opacity": "1"}, 700);
$("#test2 p").delay(3000).animate({"opacity": "1"}, 700);

CSS

#test p {
opacity: 0;
margin-top: 25px;
font-size: 21px;
text-align: center;
}
#test2 p {

opacity: 0;
margin-top: 25px;
font-size: 21px;
text-align: center;
}

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="../js/smallblocks.js" type="text/javascript"></script>
<link type="text/css" rel="stylesheet" href="../css/kqsolo.css"/>
</head>
<body>
<div id="test"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
<div id="test2"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

在加载内容后启动脚本:

$(document).ready(function() {

$("#test p").delay(1000).animate({"opacity": "1"}, 700);
$("#test2 p").delay(3000).animate({"opacity": "1"}, 700);

});

我测试了它并且它正在工作。如果没有,则错误可能在 smallblocks.js 内。尝试删除它并测试它是否改变了什么

好的,您的完整代码:

<script src="http://code.jquery.com/jquery-1.10.1.js"></script>

<style>
    #test p {
    opacity: 0;
    margin-top: 25px;
    font-size: 21px;
    text-align: center;
    }
    #test2 p {

    opacity: 0;
    margin-top: 25px;
    font-size: 21px;
    text-align: center;
    }
</style>

 <div id="test"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
<div id="test2"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>


<script>
$(document).ready(function() {
    $("#test p").delay(1000).animate({"opacity": "1"}, 700);
    $("#test2 p").delay(3000).animate({"opacity": "1"}, 700);
});
</script>

答案 1 :(得分:1)

尝试fadeIn()并显示:none;最初是关于你的物品

http://jsfiddle.net/blackjim/a9dnW/419/

setTimeout(function(){
    $("#test p").fadeIn(700);
},1000);

setTimeout(function(){
    $("#test2 p").fadeIn(700);
},3000);