2014-01-13 53 views
0

所以这里是我的问题,我想延迟4秒后出现一个图像,但这只是不起作用,你能帮忙吗?在我的代码下面;jQuery淡入不工作

HTML(index.html的):

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<style type="text/css"> 
@font-face { font-family: DayZ; src: url('DayZ.ttf'); } 
h3 { 
color: #961515; 
font-size: 32px; 
text-align: center; 
font-family: DayZ 
} 
</style> 
<meta charset="utf-8"> 

<title>Welcome to DayZ</title> 
<link rel="shortcut icon" href="http://dayzgame.com/assets/img/favicon.ico"> 
<link rel="stylesheet" type="text/css" href="css/fadein.css"> 


<script src="scripts/fadein.js"></script> 
<script src="scripts/button_fade.js"></script> 
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 



</head> 
<body> 

<audio autoplay> 
<source src="intro.mp3" type="audio/mpeg"> 
<source src="intro.ogg" type="audio/ogg"> 
<embed height="50" width="100" src="horse.mp3"> 
</audio> 

<div id="vertical"></div> 
<div id="logo"></div> 
</div> 

//this is the code for the image to display 
<img class="delayImg" delayedSrc="http://i.imgur.com/XH9NTK6.png" /> 

</body> 
</html> 

CSS(fadein.css):

.delayImg {opacity:0;} 

的JavaScript(button_fade.js):

$(document).ready(function() { 
$(".delayImg").each(function() { 
    this.onload = function() { 
     $(this).animate({opacity: 1}, 4000); 
    }; 
    this.src = this.getAttribute("delayedSrc"); 
}); 
}); 

回答

1

你需要在这个以加载脚本:

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 
<script src="scripts/fadein.js"></script> 
<script src="scripts/button_fade.js"></script> 
+0

非常感谢!这样一个愚蠢的错误!:)我现在给你的答案打个招呼:)谢谢! – Cwtch22

0
$(document).ready(function() { 
     $(".delayImg").each(function() { 
     $(this).onload = function() { 
     $(this).animate({opacity: 1}, 4000); 
    }; 
    $(this).src = $(this).getAttribute("delayedSrc"); 
    }); 
}); 

使用$(this) insted只是this

+0

感谢您的答复,但是这并不能使其工作,仍然没有任何反应,没有图像出现在所有。 – Cwtch22

+0

@ Cwtch22这与其他答案的答案将解决它,我认为 –

+0

是的,它做到了!谢谢一堆! – Cwtch22