473,783 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

rotating images with javascript prob

Hi all,
I'm trying to rotate 5 images which load from the server. My script loads
the images but when i move to the end of my array i want to cycle throught
the array again so that the images will load again in succession. At the
moment the images load through once and then stop on the first one. How can
i make my code constantly cycle throuhg the images and not stop once it has
gone through one time?
Here is my current code:

<SCRIPT language="JavaS cript">

var pic_width=300;
var pic_height=300;

if (document.image s)
{
pic1= new Image(pic_width ,pic_height);
pic1.src="http://www.ripnet.com/SilverHarbor/steveTEST/pics/pic1.jpg";
pic2= new Image(pic_width ,pic_height);
pic2.src="http://www.ripnet.com/SilverHarbor/steveTEST/pics/pic2.jpg";
pic3= new Image(pic_width ,pic_height);
pic3.src="http://www.ripnet.com/SilverHarbor/steveTEST/pics/pic3.jpg";
pic4= new Image(pic_width ,pic_height);
pic4.src="http://www.ripnet.com/SilverHarbor/steveTEST/pics/pic4.jpg";
pic5= new Image(pic_width ,pic_height);
pic5.src="http://www.ripnet.com/SilverHarbor/steveTEST/pics/pic5.jpg";
}
var pics= new Array(5)
pics[0]=pic1.src;
pics[1]=pic2.src;
pics[2]=pic3.src;
pics[3]=pic4.src;
pics[4]=pic5.src;

var numpics=5;
var thenum=0;
imgName="img1";

function change_it()
{
if (document.image s)
{
document.write( "<IMG SRC='"+pics[thenum]+"' border='0'
width='"+pic_wi dth+"' height='"+pic_h eight+"' name='img1'>\n" );
setTimeout('cha nge_it2()',1000 );
}
}

function change_it2()
{
var x=0;
thenum+=1;

if (thenum>numpics-1)
{
document[imgName].src=pics[0];
}
else
{
document[imgName].src=pics[thenum];
x+=-1;
setTimeout('cha nge_it2()',1000 );
}
}

//-->
</SCRIPT>

<body>
<SCRIPT language="JavaS cript">
<!--
change_it()
//-->
</SCRIPT>
</body>

kudos
steve
Jul 20 '05 #1
5 2714
"howdy" <me@huh.com> writes:
I'm trying to rotate 5 images which load from the server. My script loads
the images but when i move to the end of my array i want to cycle throught
the array again so that the images will load again in succession. At the
moment the images load through once and then stop on the first one.
function change_it2()
{
var x=0;
thenum+=1;

if (thenum>numpics-1)
{
document[imgName].src=pics[0];
Insert here:
thenum = 0;
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
I tried that and it is the same as before. After it has gone through all the
pics, it stops at the first pic andd oesn't rotate through again.
regards
steve

"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:vf******** **@hotpop.com.. .
"howdy" <me@huh.com> writes:
I'm trying to rotate 5 images which load from the server. My script loads the images but when i move to the end of my array i want to cycle throught the array again so that the images will load again in succession. At the
moment the images load through once and then stop on the first one.
function change_it2()
{
var x=0;
thenum+=1;

if (thenum>numpics-1)
{
document[imgName].src=pics[0];


Insert here:
thenum = 0;
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3
"howdy" <me@huh.com> writes:
I tried that and it is the same as before. After it has gone through all the
pics, it stops at the first pic andd oesn't rotate through again.


My bad. That's what happens when you post half of the solution.

Try this function:
---
function change_it2()
{
thenum++;
if (thenum >= numpics)
{
thenum = 0;
}
document[imgName].src=pics[thenum];
setTimeout(chan ge_it2,1000);
}
---
You never used "x" for anything in change_it2?

If you know you are gounf to recall change_it2 every second, you might
want to use setInterval once instead of setTimeout repeatedly.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
Yes that worked. Many thanks.
Steve
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:pt******** **@hotpop.com.. .
"howdy" <me@huh.com> writes:
I tried that and it is the same as before. After it has gone through all the pics, it stops at the first pic andd oesn't rotate through again.
My bad. That's what happens when you post half of the solution.

Try this function:
---
function change_it2()
{
thenum++;
if (thenum >= numpics)
{
thenum = 0;
}
document[imgName].src=pics[thenum];
setTimeout(chan ge_it2,1000);
}
---
You never used "x" for anything in change_it2?

If you know you are gounf to recall change_it2 every second, you might
want to use setInterval once instead of setTimeout repeatedly.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #5
JRS: In article <pt**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Sat, 25 Oct 2003 00:38:05 :-
function change_it2()
{
thenum++;
if (thenum >= numpics)
{
thenum = 0;
}
document[imgName].src=pics[thenum];
setTimeout(chan ge_it2,1000);
}


OK; or

thenum++ ; thenum %= numpics
doc ...
set ...

IMHO, it is always best to avoid if statements, provided that the
alternative is readily understandable after it has been written.

doc ... [thenum++] ; thenum %= numpics
set ...

or

doc ... [thenum = (thenum+1)%nump ics]
set ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1669
by: Fabian | last post by:
This javascript is meant for learning language vocabulary, specifically colours on this example. However, when I use images in the mtWord array, it breaks when checking for correct answers. It works fine with text in those spaces. Direct links to the pages online: http://www.lajzar.co.uk/en/colours.html http://www.lajzar.co.uk/en/animals.html How can I fix this so the functions work with images in that array? It
4
2412
by: Ian Hubling | last post by:
I'm trying to complete a rotating banner ad within a page I have. The rotating add has four images that rotate in three-second increments. I've got the images to rotate ok - but now I want to go one step further and can't figure out how to do it... I want to have it so that when the person clicks on the specific ad, they are taken to a URL that is unique to each ad. I presume I would have to surround the img tag with an href tag, but...
1
2108
by: Grunt | last post by:
Hi, I have been trying to put together a rotating banner. the code works but I am having a problem with the caching of the banner images. no matter what I try the page is constantly reloading the images, even worse they are not loading completely. This version includes a (vain) attempt at forcing the banner images to cache. Apart form the caching problem the scripting seems to work Any help welcomed:
31
7044
by: Royal Denning | last post by:
I am designing a table with 2 columns and 20 rows. I want to insert small images (each with a link) and a text title in each cell of the table. On refresh of the page, I would like to have the contents of each cell (picture/link and associated text) rotate randomly. Note that the text titles must remain with their associated picture and link (I don't want to scramble all the elements--just rotate the entire contents of the table cell).
14
6563
by: mikeoley | last post by:
Why would this script below work on an html page: http://www.eg-designdev.com/aircylinders/test.htm But not a java page such as this: "http://www.eg-designdev.com/aircylinders/index3.jsp" Or does anybody have a simple slide show rotation script they could refer me to...thanks. <HTML><HEAD>
2
2824
by: sgMuser | last post by:
Hi, I am not a good developer of Javascript codes. Needs this help to make some modification to this famous free javascript from Anarchos. i am using this in one of my webpage. What it does is, rotates banners with hyperlink specific to each image. it works just perfect but i need a simple modification. now I want to stop rotating the images when I mouseover on the image, and then continue once I move the cursor out of the banner image....
11
2155
by: bdbeames | last post by:
What I have is a is two sets of images,(Weather, optical) there is about 30 images of is each set. I have script that will rotate through the images on the main page. The user is able to view one or the other img sets with a simple onclick This works great in Mozilla but in IE I get the error documentnull or not an object, line 95, char 4. I've spent hours on this, but no luck.
6
3228
by: swethak | last post by:
Hi, I displayed the image taken from database.How to raotate that image using javascript.plz tell that how to start the logic.plz tell that some reference websites.
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
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
10147
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...
1
10083
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
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...
1
7494
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...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.