Wrox Programmer Forums
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 4th, 2003, 11:05 PM
Registered User
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple image cycling

I've got a problem with image animations. I made two images and wrote some JavaScript to change between the two every quarter second. Basically, the src attribute of the image is being changed. Anyway, I don't know how to modify the script for more than one! I thought if all of them had the same value for the name attribute, they'd all be changing. Nope, didn't work. What's the best way to get all of them to undergo the changing?

What do you see, Atrus?

Bow before me, for I am root.
Old June 6th, 2003, 02:47 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo

here's how you can do it.

var myimages = new Array('image1.gif','image2.gif','images3.gif','ima ges4.gif');

function swapIt() {
var i = 0;
if(i!=myimages.length) {
    document.getElementById('name_of_a_picture_in_html ').src = myimages[i];
    i++; }
else return false;

setTimeout("swapIt(" + i + ")",100);


remember that you need to have teh function invoked, say after document.onLoad and also have a image named "name_of_a_picture_in_html" in the html body


<img src="image1.gif" name="name_of_a_picture_in_html">

that should do it

the genuine genius

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Image Uploading? courtney_ctisn Classic ASP Basics 0 October 12th, 2007 05:35 AM
Cycling through all text boxes sjf905 C# 2 September 21st, 2006 12:43 AM
Cycling through ImageButtons spacky001 C# 2 September 3rd, 2006 04:40 AM
SetTimeout Image Cycling in Circle sasidhar79 Javascript 7 July 3rd, 2004 12:30 AM
Cycling through each record in ASP with MS Access imercha ASP.NET 1.0 and 1.1 Basics 1 March 29th, 2004 02:51 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.