0

Hi please can anybody tell me if it is possible to write a code in php that will change the image being display on my website every second. In others I want three different images to display at my homepage but at intervals. Thanks

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by achiman
0

You can't change anything about the page once it is loaded with PHP. It would require javascript to do that.

1

Javascript Image Rotator:
(not PHP)
Usage:
The switchtime is milliseconds to switch (at 5 seconds right now),
The images array is an array of images to be cycled through. They can be a relative or absolute path.

/*CodeJoust Javascript Imagerotator object. */
var imgRotator = {
init: function(el){
this.timeout = setTimeout(this.rotateImg(), this.switchtime);
this.el = el;
}
switchtime: 5000,
timeout: false,
number: 0,
el: false,
images: ['img1.jpg','img2.jpg','img3.jpg'],
rotateImg: function(){
if (!this.images[this.number+1]) { this.number = this.number+1; }
else { this.number = 0; }
this.el.src = this.images[this.number];
}
};
<img onload="imgRotator.init(this)" src="initalimg.jpg" />

Edited by codejoust: n/a

0

Thanks for the reply, how can I insert the code into my php to make it run when the homepage is being display. Can I use

include_once('filename.js');
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.