0

I was wondering if someone could help with i jQuery plugin. Basically what I want to do is to fade out each image in a div and when it comes to the last visible image it should go backwards fading in.

This is what I've done so far:

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);

But pretty obviously you can see that this does not work. It starts ok and then goes back 1 image and then forward again.

Hope someone can give me a hand on this :)

2 Answers 2

1

You can create a jQuery object of images and another with the images reversed. Once you have these it should be relatively simple to do what you want. i.e. first fadeOut the set of images, then fadeIn the reverse set of images.

Here is how you get the objects:

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

Regards Neil

0

Fixed it myself :)

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.