I've written a small piece of code to scroll through images in an array and fade in and out of each image (a slideshow).
I have a div, with an image inside which is the same size. By changing the image.src and div.backgroundImage and then adjusting the opacity I can transition the images.
It works fine in firefox and safari but special-needs IE won't update the images on this line (line 15) of code;-
Expand|Select|Wrap|Line Numbers
- div.style.backgroundImage="url('" + pictures[next] + "')";
Expand|Select|Wrap|Line Numbers
- <!--
- var pictures=["http://bytes.com/images/1.jpg","http://bytes.com/images/2.jpg","http://bytes.com/images/3.jpg","http://bytes.com/images/4.jpg","http://bytes.com/images/5.jpg","http://bytes.com/images/6.jpg","http://bytes.com/images/7.jpg","http://bytes.com/images/8.jpg","http://bytes.com/images/9.jpg"];
- var opacity = 100;
- var fadetime = 50; // milliseconds between each of the fade states
- var fadestep = 5; // reduction in opacity (from 100) for each fade state - lower number = smoother transition
- var betweentime = 7000 // milliseconds between changing images
- var current = 0;
- var next = 1;
- function startslideshow()
- {
- opacity = 100; // set opacity level back too 100%
- div = document.getElementById('slideshow'); // name the div for easy reference
- div.style.backgroundImage="url('" + pictures[next] + "')"; // set div background image as next image
- $ = document.getElementById('image'); // image name for refernce later
- $.src = pictures[current]; // Set the image source to the current image
- changeopacity(); // kick off the function to change the opacity
- }
- function changeopacity()
- {
- $ = document.getElementById('image'); // Image name for reference later
- opacity = opacity-fadestep; // set the opacity level for this stage of changing the opacity
- $.style.opacity = opacity/100; // opacity for all browsers.
- $.style.MozOpacity = opacity/100;
- $.style.KhtmlOpacity = opacity/100;
- $.style.filter = 'alpha(opacity='+ opacity + ')';
- if(opacity <= 0)
- {
- $.src = pictures[next];
- if (current == pictures.length-1) current = 0;
- else current++;
- if (next == pictures.length-1) next = 0;
- else next++;
- opacity = 100;
- setTimeout("startslideshow()",betweentime);
- return;
- }
- else setTimeout("changeopacity()",fadetime);
- }
- //-->
I also attached the whole site if this helps :-)