SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with a Script

    Hi! Thanks in advance for any help!

    I have found this nice background rotator:

    Code:
    <style>
    body
    {
    /*Remove below line to make bgimage NOT fixed*/
    background-color:black;
    background-attachment:fixed;
    background-repeat: no-repeat;
    /*Use center center in place of 300 200 to center bg image*/
    background-position: 300 200;
    width:100%; 
    height:100%; 
    overflow:hidden;
    }
    </style>
    <script language="JavaScript1.2">
    
    
    
    /* you must supply your own immages */
    var bgimages=new Array()
    bgimages[0]="URL"
    bgimages[1]="URL"
    bgimages[2]="URL"
    
    //preload images
    var pathToImg=new Array()
    for (i=0;i<bgimages.length;i++)
    {
      pathToImg[i]=new Image()
      pathToImg[i].src=bgimages[i]
    }
    
    var inc=-1
    
    function bgSlide()
    {
      if (inc<bgimages.length-1)
        inc++
      else
        inc=0
      document.body.background=pathToImg[inc].src
    }
    
    if (document.all||document.getElementById)
      window.onload=new Function('setInterval("bgSlide()",9000)')
    </script>
    But i have a little problem... when i run it, i have to wait the 9000 timer to c the first image, and i need the page to start with an image and then start the rotation, i have assigned background-image by css, and tried also to use document.body.background, but when i do this the rotator doesnt work.

    Any idea how to tweak this script for do the magic?

    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try replacing
    window.onload=new Function('setInterval("bgSlide()",9000)')

    with
    window.onload=new Function('bgSlide(); setInterval("bgSlide()",9000)')

  3. #3
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clairs View Post
    Try replacing
    window.onload=new Function('setInterval("bgSlide()",9000)')

    with
    window.onload=new Function('bgSlide(); setInterval("bgSlide()",9000)')
    Hey! TYVM my friend! This do the magic!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not a problem


Tags for this Thread

Bookmarks

Posting Permissions

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