Home arrow JavaScript arrow Page 2 - Create Your Own DHTML Slideshow With a Fading Effect
JAVASCRIPT

Create Your Own DHTML Slideshow With a Fading Effect


Looking to add an image slideshow to your family or business web site? In this article Martin shows us exactly how it's done using DHTML...

Author Info:
By: Martin Tsachev
Rating: 4 stars4 stars4 stars4 stars4 stars / 44
December 14, 2002
TABLE OF CONTENTS:
  1. · Create Your Own DHTML Slideshow With a Fading Effect
  2. · The Script
  3. · The Slideshow Script
  4. · The Slideshow Script (contd.)
  5. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Create Your Own DHTML Slideshow With a Fading Effect - The Script
(Page 2 of 5 )

The HTML

<h1>My DHTML slideshow gallery</h1>
<div align="center">
<a href="javascript:changeSlide(-1)">Previous</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:changeSlide(1)">Next</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:setFade(false)">No fade</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:setFade(true)">Fade</a><br>
</div>

<div id="slide0" class="slide">
<img src="slide0.jpg" alt="slide0" width="100" height="50">
</div>
<div id="slide1" class="slide">
<img src="slide1.jpg" alt="slide1" width="100" height="50">
</div>
<div id="slide2" class="slide">
<img src="slide2.jpg" alt="slide2" width="50" height="100">
</div>
<div id="slide3" class="slide">
<img src="slide3.jpg" alt="slide3" width="100" height="50">
</div>


This code is simple, but it works. Of course you do not have to name your images slide0.jpg and so on.

The Style Sheet

<style type="text/css">
.slide {
position : absolute;
visibility : hidden;
top : 200px;
left : 50px;
}

#slide0 {
visibility : visible;
}
</style>


Maybe you’re wondering why I didn't set the clipping in the style sheet? The answer is simple: Netscape Navigator 4 can only get the height/width of the block (actually the clipping area), when no clipping is set (apparently it doesn't get the height value properly, but I have never seen a difference of more than 10 pixels).


Explanation
Firstly, the controls are set using anchors:

<div id="slide0" class="slide">
<img src="images/slide0.jpg" alt="slide0" width="100"
height="50" border="0"></div>


This sets the first slide of your DHTML slideshow. The img should be wrapped in a div because NN 4 considers only div's and span's for layers. The case is that NN 4 can only set visibility/clipping of a layer. The class="slide" is for setting the position and visibility of all slides, and the id is to identify the slide that needs to be viewed.

.slide {
position : absolute;
visibility : hidden;
top : 200px;
left : 50px;
}

#slide0 {
visibility : visible;
}


Firstly, the class definition for all of the slides. It sets the position to absolute to get the impression that the next slides comes from below the previous one (so that the user doesn't have to scroll down the page to see the next slide).

visibility : hidden

... prevents the browser from visualizing the slides on the screen, while still reserving the space needed to actually display them. We also set the top and left co-ordinates of the slides (px is short for pixels).
blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials