December 27, 200817 yr When a webpage is being viewed, I would like one of the images in the page to change after a few seconds to another one. Ie, say, 10 images displayed on a rotating basis. How can this be done in html or php please?
December 27, 200817 yr When a webpage is being viewed, I would like one of the images in the page to change after a few seconds to another one. Ie, say, 10 images displayed on a rotating basis.How can this be done in html or php please? hi is then any use to you http://www.dyn-web.com/code/rotate_images/demos.php
December 28, 200817 yr Basically it can't be done in PHP or HTML. Both HTML and PHP are "static", so to speak. PHP does everything on the server, then stops. HTML loads it all onto your PC, then stops. Javascript is the most ideal way to create this rotation of images. Of course Javascript can be embedded within HTML-text, so sorry to say all that if you already knew. Anyhow- A simple code I'd construct for this is using setTimeout(function,time); var imageSrc=null; var image=0; var noOfImages=4; function changeImage(){ image++; if(image > noOfImages){ image=1; } if(image==1){ imageSrc="http://www.imagesite.com/image1.png"; } if(image==2){ imageSrc="http://www.imagesite.com/image2.png"; } if(image==3){ imageSrc="http://www.imagesite.com/image3.png"; } if(image==4){ imageSrc="http://www.imagesite.com/image4.png"; } document.getElementById("Image").src=imageSrc; setTimeout(changeImage(), 500); } setTimeout(changeImage(), 500); (Ever so sorry if there's a minor-code flaw in there, I'm just writing it out freely into this reply-box, haven't tested it). Basically setTimeout(function, time); carries out a set function after the set time, which is measured in milliseconds (I think). Hope this helps
Create an account or sign in to comment