此代码无限交替 2 个图像,它的工作原理:
<img src="../images/opisSlike/nagrada2a.jpg" class = "nag2altImg" alt=""/>
<img src="../images/opisSlike/nagrada2b.jpg" class = "nag2altImg2" alt=""/>
//second image starts with opacity 0
<script type="text/javascript">
function myAnimate(){
$('img.nag2altImg').delay(2500).animate({"opacity": "0"}, 1500);
$('img.nag2altImg').delay(2500).animate({"opacity": "1"}, 1500);
$('img.nag2altImg2').delay(2500).animate({"opacity": "1"}, 1500);
$('img.nag2altImg2').delay(2500).animate({"opacity": "0"}, 1500);
// this animation lasts for 8 seconds: 2500 delay + 1500 animation + 2500 delay + 1500 animation
}
$(document).ready(myAnimate());
$(document).ready(setInterval(function() {myAnimate()}, 8000));
</script>
但我想知道,有没有更优雅的方式,可以这么说,制作这样的东西?