0

SetInterval jquery関数を使用して、いくつかの画像のスライドショーを追加しました。画像ソースは配列内に保存され、各画像の表示の時間間隔も配列に保存されます.コードは機能していますが、追加したい持続時間と不透明度を持つ各画像のフェードインとフェードアウト、どうすればできますか。使用したコードは

  //timearray- is array storing time for each image
  //imagearray- is array storing each image source
  //image_div-is div tag in which images are displayed
  // total 5 images -so used count inside setInterval

function imageshow() {
    var imgfade = setInterval(function () {
        $("#img_div").css("background", "url('" + imagearray[count] + "')");
        clearInterval(imgfade);
        if (count < 4) {
            count++;
        } else {
            count = 0;
        };
        imageshow()
    }, timearray[count]);
}

imageshow();

画像ごとに、fadeIn と FadeOut を使用する必要があります。

4

3 に答える 3

0

問題を明確にするコメントに基づいて、それはfadeToあなたが望む機能であるように見えます。http://api.jquery.com/fadeTo/

于 2013-01-31T06:20:05.613 に答える
0

使用できません。アニメーション、長さ、不透明度も設定できると思います。

http://api.jquery.com/fadeIn/およびhttp://api.jquery.com/fadeOut/

于 2013-01-31T05:28:30.133 に答える
0

次の画像をフェードインする前に現在の画像をフェードアウトしたい場合は、次の行を置き換えます。

$("#img_div").css("background", "url('" + imagearray[count] + "')");

と:

var $imgDiv = $("#img_div");
$imgDiv.fadeOut("fast", function () {
    $imgDiv.css("background", "url('" + imagearray[count] + "')").fadeIn("fast");
});
于 2013-01-31T05:35:55.670 に答える