1

我有一个带有几张图片的幻灯片。它有效,但有一个小缺点。图像全部淡出。让我解释一下:第一个图像淡入并再次淡出。然后第二个图像淡入淡出。接下来是第三张图像,它再次淡入淡出。问题是在第一张图像淡出和第二张图像淡入之间,什么都没有显示。我想淡入第一张图像,然后在第一张图像上淡入第二张图像,依此类推。这样,图像的褪色之间就没有“任何东西”。

我如何调整以下代码?

html:

<div class="slideshow"></div>

Javascript

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
var images=new Array('http://placehold.it/450x450','http://placehold.it/250x150/123456','http://placehold.it/250x150/dbca98');
var nextimage=0;

doSlideshow();

function doSlideshow()
{
    if($('.slideshowimage').length!=0)
    {
        $('.slideshowimage').fadeOut(1500,function(){slideshowFadeIn();$(this).remove()});
    }
    else
    {
        slideshowFadeIn();
    }
}
function slideshowFadeIn()
{
    $('.slideshow').prepend($('<img class="slideshowimage" src="'+images[nextimage++]+'" style="display:none">').fadeIn(1500,function(){setTimeout(doSlideshow,1500);}));
    if(nextimage>=images.length)
        nextimage=0;
}
});//]]>  

</script>

CSS

<style type='text/css'>
    .slideshow
{
    position: absolute;
    width: 455px;
    height: 450px;
}
.slideshow img
{
    position: absolute;
    width: 455px;
    height: 450px;
    z-index:1;
}
  </style>

您可以在小提琴中找到代码:脚本

4

2 回答 2

0

确实有一些函数被称为这样做......对于一个便宜的解决方案,将 slideshowFadeIn() 放在你的第一个“if”语句中的 fadeOut() 调用下。

于 2012-06-18T16:49:58.463 回答
0

您需要做的就是移动您的“幻灯片淡入淡出”;

http://jsfiddle.net/R4ZHX/195/

if($('.slideshowimage').length!=0)
{
    $('.slideshowimage').fadeOut(1500,function(){$(this).remove()});
    slideshowFadeIn();
}
else
{
    slideshowFadeIn();
}
于 2012-06-18T16:48:09.253 回答