473,387 Members | 1,573 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,387 software developers and data experts.

Image array setInterval

I wanna put some images on my page that change everyfew seconds or so. The problem is that when the "slideshow" begins the veryfirst image is a blank and then it goes into the show. How do I get rid of the first blank?
Heres the code:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4.  
  5. <head>
  6. <title>HomeArray</title>
  7.  
  8. </head>
  9.  
  10. <body onLoad="slideshow()">
  11.  
  12. <script language="JavaScript">
  13.  
  14. pix = new Array();
  15.  
  16. pix[0] = "cat.jpg";
  17. pix[1] = "cat1.jpg";
  18. pix[2] = "cat2.jpg";
  19. pix[3] = "cat3.jpg";
  20.  
  21. var i = 0;
  22.  
  23. function slideshow(){
  24. setInterval("change()", 1000);
  25. }
  26.  
  27.  
  28. function change(){
  29. document.images.pic.src = pix[i];
  30. i = i + 1;
  31. if (i > (pix.length-1)) {i = 0} 
  32. }
  33.  
  34. </script>
  35.  
  36. <DIV style="position: absolute; top:00px; left:00px; border:0px solid brown;">
  37. <img name="pic" src=change() width=308>
  38. </DIV>
  39.  
  40. </body>
  41.  
  42. </html>
Aug 19 '07 #1
2 5319
phvfl
173 Expert 100+
Hi,

When the slideshow() function is called it does not show an image until after the 1000ms timeout has completed. Someone may correct me but I do not think that javascript can be used in the src attribute of an image.

There are two things that you can consider here, firstly assign an image file as the source of the image tag:
Expand|Select|Wrap|Line Numbers
  1. <img name="pic" src="cat.jpg" width=308>
With the code as it this would cause the first image to be displayed for two seconds and then for the images to rotate each second after that.

Specifying an image file as the source of the image is also recommended as this would mean that people without javascript enabled would still see an image.
Aug 19 '07 #2
pbmods
5,821 Expert 4TB
Heya, tequilamala.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 19 '07 #3

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

Similar topics

4
by: Tim | last post by:
Hope someone in the big wide world can help... What I want to do is have an image slideshow which automatically scrolls through a series of images very fast, then pauses when you move your mouse...
8
by: TheKeith | last post by:
I'm doing an image cycler but can't figure out why it keeps getting hung up on the third pic in the array? Here is what I have: ...
2
by: Mekon | last post by:
I have never written a line of script in my life but I need some help with it now. I have this auto generated code which I want to modify if possible The script generates a strip of...
2
by: TheKeith | last post by:
I'm having a bit of trouble with this script. I'm wondering if someone might help me. What I'm trying to do is to have a multiple image rollover whereby onmouseover, the image's source will cycle...
4
by: zborisau | last post by:
Hey good people, I've been given a problem to solve recently - and stuck with the solution for a good 4 days already. i have a link which leads to popup window. the purpose of that popup...
1
by: Marco Maroni | last post by:
How to force image refresh on client browser ? Is ti possible to force the refresh of the same image (tha was changed server-side) to the client, without user press Contrl+F5 in IE ? - Marco
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
6
by: Amy | last post by:
Hello, I have an array with 60 items in it, one for every second, But when it gets to the end of the 60 items it stops. How do I get it to start over when it gets to the end of the array? Please...
6
by: Janwillem Borleffs | last post by:
Tuxedo schreef: You can check the Image.complete property; example: img = new Image(100,100); interval = setInterval('checkcomplete()', 100); img.src = 'someimg'; function checkcomplete()...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.