Created
May 4, 2011 21:11
-
-
Save rumblestrut/956047 to your computer and use it in GitHub Desktop.
Rotating images with javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Oh sure, you could do this with jQuery, but in my early days, this is what I used ... | |
| <script> | |
| <!-- | |
| // Set slideShowSpeed (milliseconds) | |
| var slideShowSpeed = 8000 | |
| // Duration of crossfade (seconds) | |
| var crossFadeDuration = 3 | |
| // Specify the image files | |
| var Pic = new Array() // don't touch this | |
| // to add more images, just continue | |
| // the pattern, adding to the array below | |
| Pic[0] = '0.jpg'; | |
| Pic[1] = '1.jpg'; | |
| Pic[2] = '2.jpg'; | |
| // ======================================= | |
| // do not edit anything below this line | |
| // ======================================= | |
| var Dummyt | |
| var nCounterj = 0 | |
| var PicLen = Pic.length | |
| var preLoad = new Array() | |
| for (nCounteri = 0; nCounteri < PicLen; nCounteri++){ | |
| preLoad[nCounteri] = new Image() | |
| preLoad[nCounteri].src = Pic[nCounteri] | |
| } | |
| function runSlideShow(){ | |
| if (document.all){ | |
| document.images.SlideShow.style.filter='blendTrans(duration=2)' | |
| document.images.SlideShow.style.filter='blendTrans(duration=crossFadeDuration)' | |
| document.images.SlideShow.filters.blendTrans.Apply() | |
| } | |
| document.images.SlideShow.src = preLoad[nCounterj].src | |
| if (document.all){ | |
| document.images.SlideShow.filters.blendTrans.Play() | |
| } | |
| nCounterj = nCounterj + 1 | |
| if (nCounterj > (PicLen-1)) nCounterj=0 | |
| Dummyt = setTimeout('runSlideShow()', slideShowSpeed) | |
| } | |
| </script> | |
| --> | |
| ... | |
| <img src="" name='SlideShow' alt="SlideShow"> | |
| <script> | |
| runSlideShow(); | |
| </script> | |
| </a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment