Farsue Posted May 30, 2006 Share Posted May 30, 2006 I don't know if it's possible to do, but can you using javascript tell it to replace the current image by a new one every 2 seconds or any amount of time? Almost like a side show or frames for a movie. The code I have so far is listed below. Any help would be greatly appreciated, kind of new. <html><head><script type="text/javascript">function timedImage(){var t1=setTimeout("document.b1.src ="novas(base)web.jpg",2000)var t2=setTimeout("document.b1.src ="novas(secondframe)web.jpg",4000)var t3=setTimeout("document.b1.src ="novas(thirdframe)web.jpg",6000)}</script></head><body><form><input type="button" value="dance" onClick="timedImage()"><img border="0" alt="Visit W3Schools!" src="novas(base)web.jpg" name="b1" width="800" height="800" /></form></body></html> ~Farsue Link to comment Share on other sites More sharing options...
asylum Posted May 30, 2006 Share Posted May 30, 2006 <html><head><script type="text/javascript">var i=0;arr = ['novas(base)web.jpg', 'novas(base)web.jpg', 'novas(base)web.jpg'];function changeImg(){ document.b1.src = arr[i++%arr.length]; setTimeout(changeImg,2000);}</script></head><body onload="changeImg()"><form><input type="button" value="dance" onClick="timedImage()"><img border="0" alt="Visit W3Schools!" src="novas(base)web.jpg" name="b1" width="800" height="800" /></form></body></html> try that....setInterval is every 2 seconds, setTimeout is 2 seconds later but only once. And don't forget about nesting quotes and closing parenthesis Link to comment Share on other sites More sharing options...
Farsue Posted May 30, 2006 Author Share Posted May 30, 2006 It still says error on the page, don't know. I checked my images they're alright. Just out of curiosity what are you doing with the array and why is i being divided by it? sorry I'm a complete newbie.EDIT:never mind you're a genius it works thanks. I'd still like to know what the array does if you don't mind. Link to comment Share on other sites More sharing options...
asylum Posted May 30, 2006 Share Posted May 30, 2006 The array is just so you can declare all the images at one location so it makes changing things and looping easier. And the array isn't being divided by i it's being "modulused". The percent sign means to divide the left number by the right and return the remainder. It's basically used to limit values to a certain number, in this case 3. Link to comment Share on other sites More sharing options...
Farsue Posted May 30, 2006 Author Share Posted May 30, 2006 so if I had 4 images it would limit the amount of source files to 4? That way you wouldn't get a non-existent file? Why couldn't you have something greater than the array length? Link to comment Share on other sites More sharing options...
asylum Posted May 30, 2006 Share Posted May 30, 2006 In compiled languages it's called buffer overflow. And array is a series of memory locations mapped by the processor and allocated to your process. When the language does its parsing and creates instructions for the process it tells it which element to get in that segment, but if it tells it to get something outside that segment you can get very strange results.In javascript, it will simply result in an error. Since arrays are indexed starting at 0 the length represents the last index + 1 so you never want to reach the array length or you'll be accessing a null element (well, actually it's worse than null). However that is often used to add elements to an array in javascript. Like this arr[arr.length] = "new value"; Link to comment Share on other sites More sharing options...
Farsue Posted May 31, 2006 Author Share Posted May 31, 2006 so I think I'm a re re or something and sorry to take up your time, but in the code document.b1.src = arr[i++%arr.length]; wouldn't "i" eventually equal an amount that was greater than 3 (think there's three in the array) because it's an endless loop? What's stopping it from becoming 4 and then giving an answer of 4/3 or 5/3, you'd get a decimal greater than 1 then and no value for an image.appreciating the help~farsue Link to comment Share on other sites More sharing options...
asylum Posted May 31, 2006 Share Posted May 31, 2006 Hah, it's no problem.And what I was talking about with the modulus is what the percent sign is. So when I say 4%3 it doesn't mean 4/3 it means divide 4 by 3 and return the remainder so even if it becomes infinitely large the remainder will never be greater than or equal to 3. Link to comment Share on other sites More sharing options...
Farsue Posted June 1, 2006 Author Share Posted June 1, 2006 The remainder then chooses the element in the array? Link to comment Share on other sites More sharing options...
asylum Posted June 1, 2006 Share Posted June 1, 2006 Yes Link to comment Share on other sites More sharing options...
Farsue Posted June 3, 2006 Author Share Posted June 3, 2006 Thanks for all the help Link to comment Share on other sites More sharing options...
Farsue Posted June 4, 2006 Author Share Posted June 4, 2006 http://home.comcast.net/~farsue/dance3.htmlif that doesn't show anything then comcast hates me for using a ton of bandwidth, but thought you'd want to see the fruits of your labor Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now