Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Miniature slideshow for DIVs using Scriptaculous (See related posts)

<div id="slideshow1" class="slide"><div>frame 1</div></div>
<div id="slideshow2" class="slide" style="display: none"><div>frame 2</div></div>
<div id="slideshow3" class="slide" style="display: none"><div>frame 3</div></div>
<div id="slideshow4" class="slide" style="display: none"><div>frame 4</div></div>

<script type="text/javascript">
    
    start_slideshow(1, 4, 2000);
    
    function start_slideshow(start_frame, end_frame, delay) {
        setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
    }
                            
    function switch_slides(frame, start_frame, end_frame, delay) {
        return (function() {
            Effect.Fade('slideshow' + frame);
            if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
            setTimeout("Effect.Appear('slideshow" + frame + "');", 850);
            setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
        })
    }

</script>

Comments on this post

remvee posts on Jan 23, 2006 at 09:23
Very nice! I've concocted my own slideshow based own this: http://blog.remvee.net/post/17
jacook posts on Aug 09, 2006 at 20:20
How would I use a text link to jump to the next/previous slide?
marc.gzr posts on Dec 08, 2006 at 21:58
Please help!
My site is - www.gamezrule.org - and I use this code.
But, this code makes my middle column 'flicker' or 'stutter'.

Please help me.
The code I use is:

<div id="slideshow1" class="slide"><div><a href='showarticle.php?aid=84'><img border='0' src='images/1.png' /></a></div></div>
<div id="slideshow2" class="slide" style="display: none;width: 495px;height: 150px;"><div><a href='showarticle.php?aid=55'><img border='0' src='images/2.png' /></a></div></div>
<div id="slideshow3" class="slide" style="display: none;width: 495px;height: 150px;"><div><a href='gallery.php'><img border='0' src='images/3.png' /></a></div></div>
<div id="slideshow4" class="slide" style="display: none;width: 495px;height: 150px;"><div><a href='cms'><img border='0' src='images/4.png' /></a></div></div>
<div id="slideshow5" class="slide" style="display: none;width: 495px;height: 150px;"><div><a href='http://www.gamezrule.org/showarticle.php?aid=53'><img border='0' src='images/5.png' /></a></div></div>
<script type="text/javascript">
    
    start_slideshow(1, 5, 2000);
    
    function start_slideshow(start_frame, end_frame, delay) {
        setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
    }
                            
    function switch_slides(frame, start_frame, end_frame, delay) {
        return (function() {
            Effect.Fade('slideshow' + frame);
            if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
            setTimeout("Effect.Appear('slideshow" + frame + "');", 950);
            setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 950);
        })
    }

</script>


Thanks again. :)
carsonblack posts on Jul 25, 2007 at 05:59
Hi Marc.gzr,

If you wrap all of you slideshowX divs inside of a wrapper div that has the same width and height as the images (or even a little bigger) then you won't get the flicker.

The flicker you see is the div that will be replaced disappearing and the new div getting put in it's place appearing. There is time in between those two events where there is no div being displayed so the browser thinks there's nothing there and adjusts accordingly. The wrapper div will maintain that space throughout the replacement process and keep the flicker from happening.

Thanks for the snippet peter!
cdobbs posts on Sep 17, 2007 at 05:36
Thanks bro...you read my mind!

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts