473,698 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image array setInterval

15 New Member
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 5394
phvfl
173 Recognized Expert New Member
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 Recognized Expert Expert
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
17107
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 over the image. The images will flick through (at a rate of about 5 per second) then pause when the user onMouseOver's. Any help would be gratefully received. :o)
8
3903
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: ---------------------------------------------------------------------------- --------------------------------- <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
2
2382
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 thumbnails, and works quite well execpt that on dial up it is unbearably slow. The Thumbnails themselves are only 10kb but the total of them is a lot larger. and it appears to need to load them all before it will display any.
2
5648
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 through a few pics and stop. I got this part to work fine--it's the onmouseout part that I'm having some difficulties with. I would like everything to be included within one function, instead of two (one for mouseover and one for mouseout). Here is...
4
44077
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 window is to redirect user to the one of available servers. so i need to check which server is available. i have decided to download some 1pixel image from every server and if it was downloaded
1
10855
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
29402
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
1396
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 let me know, thank you very much. arr = new Array( ,,//to 60 items. , );
6
1267
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() { if (window.complete) {
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.