Javascript 淡出,淡出,停止

Javascript 淡出,淡出,停止,javascript,jquery,fadein,fadeout,Javascript,Jquery,Fadein,Fadeout,如何使图像淡入并停止使用下面的代码?我要补充什么? 提前感谢您的正确回答,非常感谢 HTML: JQuery: <script type="text/javascript" src="js/package/jquery-1.7.2.min.js"></script> <script type="text/javascript"> $next = 1; // fixed, please do not modfy; $curr

如何使图像淡入并停止使用下面的代码?我要补充什么? 提前感谢您的正确回答,非常感谢

HTML:


JQuery:

<script type="text/javascript" src="js/package/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    $next = 1;          // fixed, please do not modfy;
    $current = 0;       // fixed, please do not modfy;
    $interval = 4000;   // You can set single picture show time;
    $fadeTime = 800;    // You can set fadeing-transition time;
    $imgNum = 5;        // How many pictures do you have

    $(document).ready(function(){
        //NOTE : Div Wrapper should with css: relative;
        //NOTE : img should with css: absolute;
        //NOTE : img Width & Height can change by you;
        $('.fadeImg').css('position','relative');
        $('.fadeImg img').css({'position':'absolute','width':'332px','height':'500px'});

        nextFadeIn();
    });

    function nextFadeIn(){
        //make image fade in and fade out at one time, without splash vsual;
        $('.fadeImg img').eq($current).delay($interval).fadeOut($fadeTime)
            .end().eq($next).delay($interval).hide().fadeIn($fadeTime, nextFadeIn);

        // if You have 5 images, then (eq) range is 0~4 
        // so we should reset to 0 when value > 4; 
        if($next < $imgNum-1){ $next++; } else { $next = 0;}
        if($current < $imgNum-1){ $current++; } else { $current =0; }
    };
</script>

$next=1;//固定,请不要修改;
$current=0;//固定,请不要修改;
$interval=4000;//您可以设置单画面显示时间;
$fadeTime=800;//您可以设置淡入淡出过渡时间;
$imgNum=5;//你有多少张照片
$(文档).ready(函数(){
//注意:Div包装应该使用css:relative;
//注:img应与css:absolute搭配使用;
//注:img宽度和高度可由您更改;
$('.fadeImg').css('position','relative');
$('.fadeImg').css({'position':'absolute','width':'332px','height':'500px'});
nextFadeIn();
});
函数nextFadeIn(){
//使图像一次淡入淡出,无飞溅视觉;
$('.fadeImg').eq($current).延迟($interval).淡出($fadeTime)
.end().eq($next).delay($interval).hide().fadeIn($fadeTime,nextFadeIn);
//如果有5幅图像,则(eq)范围为0~4
//因此,当值>4时,我们应该重置为0;
如果($next<$imgNum-1){$next++;}否则{$next=0;}
如果($current<$imgNum-1){$current++;}否则{$current=0;}
};

最简单的选择是在
$current
匹配
$imgNum
时停止:

 function nextFadeIn() {
    if ($current >= $imgNum) return;
    //make image fade in and fade out at one time, without splash vsual;

尽管纯粹主义者可能不喜欢这一点,因为这意味着nextFadeIn()的额外迭代,但它应该以最小的更改涵盖您需要的内容。

我在代码中复制并粘贴了这一点,并将名称fadeImg更改为TopHeroMage,这是我的类的名称。我还使用了两个不是5的图像,所以我更改了$imgNum=2。我对javascript非常陌生,但我正在学习。我知道有一种方法可以添加。停止它,我只是不知道在哪里使它停止循环。您声明的要求似乎与代码不匹配。只需执行
$(“#id”).fadeIn()。也许你可以解释一下你想做什么,以及为什么你认为这个插件解决了这个问题,而不是简单的代码。下面是我一直在编写的代码:顶部的头图像有循环png,我不知道如何编写JavaScript或jquery,所以我在25sproutLab上发现了它,从第一个png开始,到第二个png,它似乎工作得很好淡入下一个png,但是我不知道如何使它在第二个图像上停止,并保持停止而不是循环。我不知道如何写完整的代码。很抱歉,我是新手。我很感激你能和我一起解决这个问题@自由麻省理工学院很遗憾你发现了这段代码,它不是特别优雅,可能会给你带来一些不好的习惯。在学习过程中,请继续查看其他代码。但最重要的是,确保你学习愉快。非常感谢,我会尝试添加这些内容,看看会发生什么,我肯定很开心,当一切正常时,这绝对是最令人满意的。
 function nextFadeIn() {
    if ($current >= $imgNum) return;
    //make image fade in and fade out at one time, without splash vsual;