Connecting Tech Pros Worldwide Forums | Help | Site Map

Image Slide Show

Member
 
Join Date: Nov 2006
Posts: 53
#1   Jul 4 '07
Greetings everyone,

I´ve developed a script to make a slideshow using a holder and the images you need. Just place the images you need within a holder, pass the holder ID to the script and its done!

the parameters are:
holder - id of the holder
speed - change this number to increase/increase speed (lower = faster)
width - width of the holder / images within
height - height of the holder / images within

Expand|Select|Wrap|Line Numbers
  1. //////////////////////////////////////
  2. // Romulo do Nascimento Ferreira     //
  3. //         romulo.nf@gmail.com            //
  4. //////////////////////////////////////
  5.  
  6. function makeSlideShow(holder,speed,width,height) {
  7. gallery = document.getElementById(holder)
  8. gallery.style.width = width + "px"
  9. gallery.style.height = height + "px"
  10. gallery.style.cssFloat = "left"
  11. this.alphaShow = 0
  12. this.alphaFade = 100
  13. this.currentImg = 0
  14. this.animationSpeed = speed
  15. this.images = gallery.getElementsByTagName("img")
  16. this.galleryLength = this.images.length
  17.  
  18.     for (x=0; x<this.galleryLength; x++) {
  19.     this.images[x].style.width = width + "px"
  20.     this.images[x].style.height = height + "px"
  21.     this.images[x].style.position = "absolute"
  22.  
  23.     this.images[x].style.filter = "alpha(opacity=0)"
  24.     this.images[x].style.opacity = "0"
  25.     this.images[x].style.mozOpacity = "0"
  26.     }
  27.  
  28. var _this = this
  29. var startShow = window.setInterval(function(){_this.engine()},this.animationSpeed*10)
  30. }
  31.  
  32. makeSlideShow.prototype.engine = function() {
  33. this.nextImage = this.currentImg + 1 < this.galleryLength ? this.currentImg + 1 : 0
  34.  
  35. this.images[this.currentImg].style.filter = "alpha(opacity=" + this.alphaFade + ")";
  36. this.images[this.currentImg].style.opacity = this.alphaFade < 10? "0.0" + this.alphaFade : this.alphaFade >= 10 && this.alphaFade < 100 ? "0." + this.alphaFade : 1.0;
  37. this.images[this.currentImg].style.mozOpacity = this.alphaFade < 10? "0.0" + this.alphaFade : this.alphaFade >= 10 && this.alphaFade < 100 ? "0." + this.alphaFade : 1.0;
  38.  
  39. this.images[this.nextImage].style.filter = "alpha(opacity=" + this.alphaShow + ")";
  40. this.images[this.nextImage].style.opacity = this.alphaShow < 10? "0.0" + this.alphaShow : this.alphaShow >= 10 && this.alphaShow < 100 ? "0." + this.alphaShow : 1.0;
  41. this.images[this.nextImage].style.mozOpacity = this.alphaShow < 10? "0.0" + this.alphaShow : this.alphaShow >= 10 && this.alphaShow < 100 ? "0." + this.alphaShow : 1.0;
  42.  
  43. this.alphaFade = this.alphaFade - 2
  44. this.alphaShow = this.alphaShow + 2
  45.  
  46.     if (this.alphaFade == 100 || this.alphaShow == 100) {
  47.     this.alphaFade = 100
  48.     this.alphaShow = 0
  49.     this.currentImg = this.currentImg + 1 > this.galleryLength-1 ? 0 : this.currentImg + 1
  50.     }
  51. }
  52.  
To make the script work you will need a holder with images like:
Expand|Select|Wrap|Line Numbers
  1. <div id="galeria1">
  2. <img src="t1.jpg">
  3. <img src="t2.jpg">
  4. <img src="t3.jpg">
  5. </div>
  6.  
And make the call:
Expand|Select|Wrap|Line Numbers
  1. new makeSlideShow('galeria1',4,150,100)
  2.  
Feel free to modify anything, just let my name there :P
Any questions use the email on the code!

Good luck



Newbie
 
Join Date: Aug 2007
Location: Manalapan, NJ
Posts: 1
#2   Aug 27 '07

re: Image Slide Show


Romulo,
I meant to say that it was a smart way of anchoring images in a slideshow.
thanks.
Jean-Pierre
Reply


Similar JavaScript / Ajax / DHTML bytes