一份简单的轮播图代码

<!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>图片轮播切换</title>
<style type="text/css">

#banner_lun_bo_img_box{
	width:960px;
	height:314px; 
	margin: 0 auto; 
	position:relative;
}
#banner_lun_bo_a{
	display: block; 
	width:100%; 
	height:100%;
}
#banner_lun_bo_img{
	display:block;
	width:auto;
	height:auto;
	max-width:100%;
	max-height:100%;
}

#banner_lun_bo_img_desc{
	position:absolute; 
	left: 5px; 
	bottom:5px;
	color:#FFF;
}
.banner_lun_bo_img_ul li
{
	float: left;
	width:20px;
	height:20px;
	border: 1px dashed  #aaa;
	margin: 5px;
	padding: 0;
	list-style:none;
	background-color: white;
	color:black;
	text-align: center;
}
.banner_lun_bo_img_ul li a{
	color: black;
	text-decoration: none;
	padding: 0;
	display: inline-block;
	width: 100%;
	height: 100%;
}


</style>

</head>

<body>

<div id="banner_lun_bo_img_box">
	 <a href="javascript:;" id="banner_lun_bo_a">
	 		<img src="imgs/banner_lun_bo_1.jpg" id="banner_lun_bo_img"/>
	 </a>
	<h1 id="banner_lun_bo_img_desc">大象守护者项目带孩子们走进动物园</h1>
	<div style="position:absolute; right: 5px; bottom:0px;color:#FFF;">
		<ul class="banner_lun_bo_img_ul">
			<li>
				<a href="javascript:;" id="banner_lun_bo_a_1" onclick="setLunBoImage(0)">1</a>
			</li>
			<li id="banner_lun_bo_li_2">
				<a href="javascript:;" id="banner_lun_bo_a_2" onclick="setLunBoImage(1)">2</a>
			</li>
			<li id="banner_lun_bo_li_3">
				<a href="javascript:;" id="banner_lun_bo_a_3" onclick="setLunBoImage(2)">3</a>
			</li>
		</ul>
	</div>
</div>
	
	 



</body>

<script type="text/javascript" language="javascript">

// 图片轮播代码 start
var lun_bo_imgs = new Array();
lun_bo_imgs[0] = {img: "imgs/banner_lun_bo_1.jpg", a: "banner_lun_bo_a_1", desc: "大象守护者项目带孩子们走进动物园"};
lun_bo_imgs[1] = {img: "imgs/banner_lun_bo_2.jpg", a: "banner_lun_bo_a_2", desc: "古道尔博士在2010年根与芽中国峰会上与学生们在一起"};
lun_bo_imgs[2] = {img: "imgs/banner_lun_bo_3.jpg", a: "banner_lun_bo_a_3", desc: "水地图小组植物调查"};

var lun_bo_img_index = 0;
function lunBoImgage(){
   if(lun_bo_img_index >= lun_bo_imgs.length) lun_bo_img_index = 0;
   setLunBoImage(lun_bo_img_index);
   lun_bo_img_index += 1;
}


function setLunBoImage(index)
{
   if(index < 0 || index >= lun_bo_imgs.length) index = 0;
   var tagImg = document.getElementById("banner_lun_bo_img");
   tagImg.src = lun_bo_imgs[index].img;
   tagImg.title = lun_bo_imgs[index].desc;
   tagImg.alt = lun_bo_imgs[index].desc;
   document.getElementById("banner_lun_bo_img_desc").innerHTML = lun_bo_imgs[index].desc;
   document.getElementById(lun_bo_imgs[index].a).style.backgroundColor = "#003300";
   document.getElementById(lun_bo_imgs[index].a).style.color = "white";
   for(var i = 0; i < lun_bo_imgs.length; i++)
   {
   		if(index != i)
   		{
   			document.getElementById(lun_bo_imgs[i].a).style.backgroundColor = "white";
   			document.getElementById(lun_bo_imgs[i].a).style.color = "black";
   		}
   }
}

 var timerLunBo = setInterval(lunBoImgage, 2000); 
 var banner_lun_bo_img_box = document.getElementById("banner_lun_bo_img_box");
 banner_lun_bo_img_box.onmouseover = function () { clearInterval(timerLunBo) };		
 banner_lun_bo_img_box.onmouseout = function ()  { timerLunBo = setInterval(lunBoImgage, 2000) };
 
// 图片轮播代码 end //////////////////////////////////////////////////////////////



</script>

</html>





评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

friendan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值