0

jQuery Backgrounder Pluginをスライドショーとして使用しようとしていますが、うまくいきません。どんな種類の助けでも本当に感謝しています。ありがとう。ここに私がこれまでに持っているものがあります:

HTML:

<div id="my_background">
   <img src="/img/main/home.jpg" />
   <img src="/img/main/home-2.jpg" />
</div>

jQuery 呼び出し:

$(function() {
      setInterval( $('#my_background').backgrounder({element : '#content-bg'}) , 5000 );
    });

jQuery プラグイン

改行

var img = $(this).children('img').first();

var img = $(this).children('img').next();

5秒ごとに画像を切り替える必要がありますが、機能しません。私は何を間違っていますか?

4

1 に答える 1

1

プラグインコードを変更しなくても、このような方法でうまくいくはずです:

http://jsfiddle.net/WZ3TL/

HTML

<div id="my_background"></div>
<div id="content-bg"></div>
​

JS

$(function() {

    //list of images
    var images = [
        'http://flickholdr.com/1200/600/landscape/bw',
        'http://flickholdr.com/1200/600/landscape/2'
    ];

    function rotate(){

        //get first images from the list
        var img = images.shift();
        //put it a the end of the list again
        images.push(img);

        //put image in source container
        $('#my_background').html('');
        $('<img/>').attr('src', img).appendTo($('#my_background'));

        //call backgrounder (again)
        $('#my_background').backgrounder({
            element: '#content-bg'
        });
    }

    //initial call
    rotate();

    //call in interval
    setInterval( rotate, 1000 );
});

</p>

于 2012-07-30T15:58:56.507 に答える