简单实现 图片轮流显示 全部代码

本文介绍了一种使用JavaScript实现的简单图片轮播效果。通过预加载图片并设置定时器来自动切换显示的图片,用户可以自定义图片切换的时间间隔。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

全部代码如下:

注意要在pic文件下放入10个图片,名字为:pic1.jpg、pic2.jpg......pic9.jpg

<?xml version="1.0" encoding="UTF-8"?>
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.ajax4jsf.org/rich">
<head>
<title>后台管理</title>

<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description"
content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

</head>
<body>
<style type="text/css">
<!--

td {font-family: Verdana, Arial, sans-serif, Helvetica; font-size: 12px; color: #F0F0F0;}
a {font-family: Verdana, Arial, sans-serif, Helvetica; font-size: 12px; color: #F0F0F0; text-decoration: none}
#btnStyle {font-family: Verdana, Arial, sans-serif, Helvetica; font-size: 12px; background-color: #C0C020; border-top: 0px solid; border-bottom: 0px solid; border-left: 0px solid; border-right: 0px solid;}

//--></style>
<script language="JavaScript" type="text/JavaScript"><!--

var img = new Array(10); //array to hold the images
var start = null; //start pointer
var counter = 1; //counts the image sequences
var delayTime = null; //user defined


if(document.images) //pre-load all the images
{
/* change the looping condition if you want
to add or remove images. Do not load too
many images, it will slow down the program's
loading time [e.g. 30 or above images] */

for(i = 1; i <= 10; i++)
{
img[i] = new Image();
img[i].src = "../images/pic/pic" + i + ".jpg";
}
}


//function for getting the user defined delay time
function getDelayTime(dlTime)
{
var temp = parseInt(dlTime);
if(temp != NaN)
delayTime = temp * 1000;

else
delayTime = 4000;
}


//function for changing the images
function anim()
{
counter++;
document.images[0].src = img[counter].src;

if(counter == 10)
counter = 0; //sets the counter value to 0
}


//function for starting the slide show
function slide()
{
getDelayTime(document.form1.delay.value);

with(document.form1)
{
start = setInterval("anim()", delayTime);
stShow.disabled = true;
spShow.disabled = false;
}
}


//function to stop the slide show
function stopSlide()
{
clearInterval(start);
document.form1.stShow.disabled = false;
document.form1.spShow.disabled = true;
}


//--></script>
<table>
<tr><td valign="top" align="center">
<img src="../images/pic/pic1.jpg" border="0" width="400" height="300" />
<form name="form1">
请输入图片显示间隔时间:
<input type="text" size="2" value="4" name="delay" />

<input type="button" value="Start Show" name="stShow" onmousemove="slide();" id="btnStyle" />
<input type="button" value="Stop Show" name="spShow" onmousemove="stopSlide();" id="btnStyle" />
</form>
</td></tr></table>


</body>
</html>


本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/guijava/archive/2008/11/04/3216914.aspx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值