gpt4 book ai didi

用于幻灯片放映的 JavaScript

转载 作者:行者123 更新时间:2023-11-28 12:43:09 26 4
gpt4 key购买 nike

有人可以建议好的 javascript 代码来实现幻灯片放映,以便幻灯片放映的所有元素都在数组中声明。我希望它使用纯 javascript 而不使用 jQuery

最佳答案

这可能对您有用。复制并替换图像。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>image slide show</title>
<style type="text/css">
body {
background:#FFC;
}
input[type="button"] {
background:#939907;
color:#fff;
border:1px solid #434603;
-moz-border-radius:5px;
-webkit-border-radius:5px;
-ms-border-radius:5px;
font-weight:bold;
cursor:pointer;
height:25px;
}
img {
width:525px;
height:200px;
border:2px solid #CF3;
-moz-border-radius:15px;
-webkit-border-radius:15px;
-ms-border-radius:15px;
}
</style>
<script type="text/javascript">
var images=new Array();
var i=0, t, f=false;

images[0] ="images/heli1.jpg";
images[1] ="images/heli2.JPG";
images[2] ="images/heli3.JPG";
images[3] ="images/heli4.JPG";
images[4] ="images/heli5.JPG";
images[5] ="images/heli6.JPG";
images[6] ="images/heli7.JPG";
images[7] ="images/heli2.JPG";
images[8] ="images/heli9.JPG";
images[9] ="images/heli1.jpg";
images[10] ="images/heli2.JPG";
images[11] ="images/heli3.JPG";
images[12] ="images/heli4.JPG";
images[13] ="images/heli5.JPG";
images[14] ="images/heli6.JPG";


function start(){
if(i>=images.length){
i=0;
document.getElementById('img').src=images[i];
i++;
}
else{
document.getElementById('img').src=images[i];
i++;
}
t=setTimeout("start()", 1000);
}
function play(){
if(f==false){
f=true;
start();
}
}

function Stop(){
clearTimeout(t);
f=false;
}

function next(){
if(i>=images.length){
i=0;
document.getElementById('img').src=images[i];
i++;
}
else{
document.getElementById('img').src=images[i];
i++;
}
}

function previous(){
if(i>=images.lenght){
i=images.length;
document.getElementById('img').src=images[i];
i--;
}
else if(i<=0){
i=images.length;
document.getElementById('img').src=images[i-1];
i--;
}
else if(i>images.length){

document.getElementById('img').src=images[images.length-i];
}
else if(i<=images.length || i>0){
document.getElementById('img').src=images[i-1];
i--;
}
}

</script>
</head>

<body>
<table width="50%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><input type="button" value="Previous" onclick="previous()" /></td>
<td align="center"><a href="#"><img src="images/heli6.JPG" alt="" id="img" /></a></td>
<td><input type="button" value="Next" onclick="next()" /></td>
</tr>
<tr>
<td colspan="3" align="center" height="50"><input type="button" value="Play" onclick="play()" />
<input type="button" value="Stop" onclick="Stop()" /></td>
</tr>
</table>
</body>
</html>

关于用于幻灯片放映的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10752383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com