473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

looping slideshow fails to change/fade image in/out

Hello, hope you have a few minutes to lend me your thoughts on why my code doesn't do anything. I'm trying to run a looping slideshow of 3 or more pictures, fading in and out. At the moment, nothing happens. The first image is displayed statically in position, no fading or changing image at all.

my code:
in the head I declare my images
Expand|Select|Wrap|Line Numbers
  1.     <script type="text/javascript">
  2.     <!--
  3.         var image1=new Image()
  4.         image1.src="media/home/image1.jpg"
  5.         var image2=new Image()
  6.         image2.src="media/home/image2.jpg"
  7.         var image3=new Image()
  8.         image3.src="media/home/image3.jpg"
  9.     //-->
  10.     </script>

and this is in the body
Expand|Select|Wrap|Line Numbers
  1. <div id="content">
  2.           <div id="slideshow"> <img src="media/home/image1.jpg"
  3.               alt="oops! The slideshow hasn't loaded! Please try
  4.               refreshing (ctrl+F5) or send us an email to let us know."
  5.               name="slide" height="410" width="600"> </div>
  6.           <div id="nextslide"> <img src="media/home/image2.jpg"
  7.               alt="oops! The slideshow hasn't loaded! Please try
  8.               refreshing (ctrl+F5) or send us an email to let us know."
  9.               name="slide" height="410" width="600"> </div>
  10.           <script type="text/javascript">
  11. <!--
  12. //if browser does not support the image object, exit.
  13. if (!document.images)
  14. return
  15. if (!document.getElementById)
  16. return
  17.  
  18. var slide1 = document.getElementById("slideshow");
  19. var slide2 = document.getElementById("nextslide");
  20. var currentpic = document.getElementById("slide1pic");
  21. var nextpic = document.getElementById("slide2pic");
  22. var changeslide = document.getElementById("slideshow").src;
  23. var duration = 3000; /* fade duration in millisecond */
  24. var showtime = 10000; /* time to stay visible */
  25. //variable that will increment through the images
  26. var step=3;
  27.  
  28. //function to update opacity/alpha filter of slide1 to a given value and of slide2 to the inverse
  29. function SetOpa(Opa) {
  30. Opa2 = 1-Opa;
  31. slide1.style.opacity = Opa;
  32. slide1.style.MozOpacity = Opa;
  33. slide1.style.KhtmlOpacity = Opa;
  34. slide1.style.filter = 'alpha(opacity=' + (Opa * 100) + ');';
  35. slide2.style.opacity = Opa2;
  36. slide2.style.MozOpacity = Opa2;
  37. slide2.style.KhtmlOpacity = Opa2;
  38. slide2.style.filter = 'alpha(opacity=' + (Opa2 * 100) + ');';
  39. }
  40.  
  41. function fade() {
  42. //fade from slide1 to halfway between 1 and 2
  43. for (i = 0; i <= 0.5; i += 0.01) {
  44. setTimeout("SetOpa(" + (1 - i) +")", i * duration);
  45. }
  46. //at halfway point, switch slide images
  47. changeslide=currentpic.src;
  48. document.images.currentpic.src=eval(nextpic.src);
  49. document.images.nextpic.src=changeslide;
  50.  
  51. //complete fade through
  52. for (i = 0.5; i <= 1; i += 0.01) {
  53. setTimeout("SetOpa(" + (1 - i) +")", i * duration);
  54. }
  55. //update nextslide
  56. document.images.slide2.src=eval("image"+(step)".src");
  57.  
  58. if(step < 3)
  59. step++;
  60. else
  61. step=1;
  62.  
  63. //call function fade() every 10 seconds
  64. setTimeout("fade()",showtime);
  65. }
  66.  
  67. fade();
  68. //-->
  69. </script>
  70. </div>
  71.  
can you tell me what i'm doing wrong?
Feb 5 '12 #1
2 1923
migi48
28
Hi clover8leaf.

Basically from your code, you are only creating the images (image1,image2, and image3). However, you have no code for diplaying those images. I suggest that you create a function:

Expand|Select|Wrap|Line Numbers
  1. function updateFullImage(id, url){
  2.      var image1 = document.getElementById(id);
  3.      img.src = url ; 
Note: Make sure you have an image tag in your HTML and have an ID.
Feb 7 '12 #2
Dormilich
8,658 Expert Mod 8TB
However, you have no code for diplaying those images. I suggest that you create a function:

Expand|Select|Wrap|Line Numbers
  1. function updateFullImage(id, url){
  2.      var image1 = document.getElementById(id);
  3.      img.src = url ; 
except for the issue that you don't change the src of the image you fetch ...
Feb 7 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Shang Wenbin | last post by:
Hi, How to use javascript in php? I want to return some values to php. Thanks -- Shang Wenbin from Realss
4
by: gattaca8 | last post by:
The following script works fine in IE...but gives me a "sBox has no properties" error in Firefox. sBox is only used in the below method. function addTop (sectId) { sBox =...
2
by: Wade H | last post by:
Hi, This is a simple question I think but I am unsure. Is it possible to combine ASP.NET scripting and JavaScript on the one page but with separate <script> tags? Thanks Heaps
1
by: cs5b | last post by:
I am looking for the official javascript security specification for web browsers. EMCAScript and DOM spec does not seem to contain a section on security, so I assume none exists and the security...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.