jQuery图像旋转器

时间:2011-02-07 14:36:11

标签: jquery

我想知道是否有人可以帮助我使用jQuery插件。基本上我想做的是淡出div中的每个图像,当它到达最后一个可见图像时,它应该向后淡入。

这是我到目前为止所做的:

setTimeout((function rotate(back) {
    if ($('img:visible', $container).length > 1) {
        $('img:visible:last', $container).fadeOut(opts.animation, function () {
            setTimeout(rotate, opts.interval);
        });
    } else {
        $('img:hidden:first', $container).fadeIn(opts.animation, function () {
            setTimeout(rotate, opts.interval);
        });
    }
}), opts.interval);

但显然你可以看到这不起作用。它开始正常,然后返回1张图像然后再转发。

希望有人可以帮我解决这个问题:)

2 个答案:

答案 0 :(得分:1)

你可以创建一个jQuery对象的图像和另一个图像反转。一旦你拥有这些,你应该做你想要的相对简单。即,首先淡出图像集,然后淡入反向图像集。

以下是获取对象的方法:

var $images = $('img', $container);           // Set of images
var $segami = $($images.toArray().reverse()); // Set of images in reverse order

此致        尼尔

答案 1 :(得分:0)

我自己修正了:)

function rotate(forward, backward) {

    if (backward == images - 1) {
        backward = 0;
        forward = images;
    }

    if (forward > 1 ) {
        forward -= 1;

        $('img:visible:last', $container).fadeOut(opts.animation, function () {
            setTimeout(function () { rotate(forward, backward) }, opts.interval);
        });
    } else {
        backward += 1;

        $('img:hidden:first', $container).fadeIn(opts.animation, function () {
            setTimeout(function () { rotate(forward, backward) }, opts.interval);
        });
    }
}

setTimeout(function () { rotate(i, i2) }, opts.interval);
相关问题