treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Can I randomize this slider?

  • I am using this jQuery slider as a way to run through ads for a clients site and since I didn't think of randomizing at first I am facing the issue now. Also I didn't keep the link to the slider and i don't have the documentation (I know what the heck was I thinking). I am hoping someone can help me to randomize these ads. Here is the code:
    <!-- Ad Slider -->
    <script type=\"text/javascript\">

    function theRotator() {
    //Set the opacity of all images to 0
    $('div#adrotator ul li').css({opacity: 0.0});

    //Get the first image and display it (gets set to full opacity)
    $('div#adrotator ul li:first').css({opacity: 1.0});

    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('rotate()',8000);

    }

    function rotate() {
    //Get the first image
    var current = ($('div#adrotator ul li.show')? $('div#adrotator ul li.show') : $('div#adrotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#adrotator ul li:first') :current.next()) : $('div#adrotator ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);

    //Hide the current image
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');

    };

    $(document).ready(function() {
    //Load the slideshow
    theRotator();
    });

    </script>
    <!-- End Ad Slider -->


    Of course there is always a different slider I can use, but since I have this one set up I figured it was worth a shot to see if it was possible with this one. If anything else is needed please let me know, and TIA!