SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding automatic random change code

    hello good pple of the forum,
    The code below is simple manual slideshow, what i need to do is to add a function that would enable the slideshow to change automatically, still leaving the manual change links
    PHP Code:
    var num=1
    img1 
    = new Image ()
    img1.src "images/one.png"
    img2 = new Image ()
    img2.src "images/two.png"
    img3 = new Image ()
    img3.src "images/three.png"
    img4 = new Image ()
    img4.src "images/four.png"
    img5=new Image()
    img5.src="images/five.png"

    function slideshowUp()
    {
    num=num+1
    if (num==6)
    {
    num=1}
    document.mypic.src=eval("img"+num+".src")
    }

    function 
    slideshowBack()
    {
    num=num-1
    if (num==0)
    {
    num=5}
    document.mypic.src=eval("img"+num+".src")

    thank you

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var intervalId = setInterval("slideShowUp", 10000);

    function slideshowUp()
    {
    clearInterval(intervalId);
    intervalId = setInterval("slideShowUp", 10000);
    num=num+1
    if (num==6)
    {num=1}
    document.mypic.src=eval("img"+num+".src")
    }

    hope this helps
    AFrieze

  3. #3
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks afrieze, but it is not working

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setInterval("slideShowUp", 10000); should have been setInterval("slideShowUp()", 10000);

    Replace the two occurences
    try that

    AFrieze

  5. #5
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks once again, but the code is still not working

  6. #6
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please pple at the forum any other suggestions
    thank you

  7. #7
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly what do you want? When should it be automatic? And when/how should that get started and stopped?

  8. #8
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like Pepejeria's suggestion should have worked - but you have some other issues with your code.

    I had a demo that was very close to what you wanted so I modified it a little. Have a look: xSlideShow

  9. #9
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't make any suggestion

  10. #10
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops! Sorry about that, AFrieze

  11. #11
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Afrieze code actually worked, i just goofed in making correction in the letter case for the functions
    Thanks Guys once again

  12. #12
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just some tips. Always try to avoid eval. Eval is evil and expensive. You could easily avoid eval by storing your images in an Array, like this:
    Code:
    var aImages = new Array();
    aImages[0] = new Image();
    aImages[0].src = "images/one.png";
    
    // etc...
    
    // Then you can avoid the eval by doing this:
    document.mypic.src = aImages[num].src;
    Same goes for the window.setInterval, instead of passing a String, pass the function:
    Code:
    window.setInterval(slideShowUp, 1000);

  13. #13
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you for the tip

  14. #14
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok guys one last question (i think). This site that i just designed, i copied off a slideshow script from dynamic drive. Now, i wondering how can i get that transition effect incorporated into the simple slideshow code i written.
    Thanks guys once again


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
  •