我知道一点点php。任何人都可以告诉我如何编写一个简单的PHP脚本,以便标题中的图像每5秒左右更改一次。我不想在该图像上放置任何类型的链接只是想要更改图像。谢谢:))
答案 0 :(得分:4)
我不太了解关于PHP的大量内容我担心但是这是一个很好的小脚本,我发现用javascript写的可能对你有帮助:
http://www.go4expert.com/forums/showthread.php?t=1012
希望有所帮助。
<html>
<head>
<title>Image Rotate
</head>
<body>
<img src="" name="Rotating" id="Rotating1" width=100 height=100>
<img src="" name="Rotating" id="Rotating2" width=100 height=100>
<script language="JavaScript">
var ImageArr1 = new Array("Picture(3).jpg","Picture(1).jpg","Picture(2).jpg");
var ImageHolder1 = document.getElementById('Rotating1');
var ImageArr2 = new Array("Picture(5).jpg","Picture(6).jpg","Picture(7).jpg");
var ImageHolder2 = document.getElementById('Rotating2');
function RotateImages(whichHolder,Start)
{
var a = eval("ImageArr"+whichHolder);
var b = eval("ImageHolder"+whichHolder);
if(Start>=a.length)
Start=0;
b.src = a[Start];
window.setTimeout("RotateImages("+whichHolder+","+(Start+1)+")",1500);
}
RotateImages(1,0);
RotateImages(2,0);
</script>
</body>
</html>
答案 1 :(得分:3)
PHP只能提供图像,你需要一些JavaScript来触发获取新图像的事件。
这是一种方法,改编自http://javascript.internet.com/miscellaneous/random-image-rotator.html:
<HTML>
<HEAD>
<!-- STEP ONE: The core of it: JavaScript... -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Robert Bui (astrogate@hotmail.com) -->
<!-- Web Site: http://astrogate.virtualave.net -->
<!-- Begin
var interval = 2.5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;
var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("http://www.something.com/image01.jpg");
image_list[image_index++] = new imageItem("http://www.something.com/image02.jpg");
image_list[image_index++] = new imageItem("http://www.something.com/image03.jpg");
image_list[image_index++] = new imageItem("http://www.something.com/image04.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
} else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "rotateImage('"+place+"')";
setTimeout(recur_call, interval);
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY OnLoad="rotateImage('rImage')">
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<center>
<img name="rImage" src="http://www.something.com/image01.jpg" width=120 height=90>
</center>
</BODY>
</HTML>