Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile Improving jquery code (simplifying it into an array?)

    I have some jquery that fades images in and out on a set time after page loads. I was hoping i could simplify it so it's easier to add more images, and make it repeat once its gone through the code once.

    This is my code. Thanks in advance. ( I know this is super easy to do )

    Code:
    $(document).ready(function(){
    setTimeout(function () {$(".p1").fadeIn("slow");}, 100);
    setTimeout(function () {$(".p1").hide("slow");}, 5100);
    setTimeout(function () {$(".p2").show("slow");}, 5300);
    setTimeout(function () {$(".p2").hide("slow");}, 8300);
    setTimeout(function () {$(".p3").show("slow");}, 8500);
    setTimeout(function () {$(".p3").hide("slow");}, 11500);
    setTimeout(function () {$(".p4").show("slow");}, 11700);
    setTimeout(function () {$(".p4").hide("slow");}, 14700);
    setTimeout(function () {$(".p5").show("slow");}, 14900);
    //setTimeout(function () {$(".p5").hide("fast");}, 6300);
    });

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    There are tons of slideshow plugins already written that handle all of this for you quite adequately.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •