Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

change (rotate) images on a timed basis

Featured Replies

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?

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

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.