0

I have a function that rotates various ads by fading in and out, but i need it to loop infinitely until someone clicks on one of the images. Here is the function

$(document).ready(function() {
    /* thumbnail ads */
    $('#adthumb1').delay(3500).fadeIn(1500).delay(9000).fadeOut(1500);
    $('#adthumb2').fadeIn(0000).delay(3500).fadeOut(1500).delay(2000).fadeIn(1500);
    $('#adthumb3').fadeIn(0000).delay(7000).fadeOut(1500).delay(2000).fadeIn(1500);
    $('#adthumb4').fadeIn(0000).delay(10500).fadeOut(1500).delay(2000).fadeIn(1500);
    /* main ads */
    $('#mainad1').fadeIn(0000).delay(3500).fadeOut(1500);
    $('#mainad2').delay(3500).fadeIn(1500);
    $('#mainad3').delay(7000).fadeIn(1500);
    $('#mainad4').delay(10500).fadeIn(1500);
});

Any help is much appreciated!!

2
  • 3
    Why don't you just build an array of your elements and then use the callback of .fadeIn() or .fadeOut() to cycle them? Commented Jun 15, 2012 at 16:23
  • I want some of the animations to overlap slightly and from what i understand, callbacks would wait for each animation to complete, correct me if im wrong. Thanks! Commented Jun 15, 2012 at 17:32

1 Answer 1

3

You can use setInterval, capture the intervalID, and use clearInterval to cancel the loop in a click handler on the div containing the rotating ads.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.