以下是 旅游网站banner滑动切换特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!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>旅游网站banner滑动切换特效</title>
<link href="style.css" type="text/css" rel="stylesheet">
<script src="focus.js" type="text/javascript"></script>
</head>
<body>
<div class="sub_box">
<div id="p-select" class="sub_nav">
<div class="sub_more"><a href="#" onfocus="this.blur()" title="查看更多目的地旅游指南" style="font-size:12px;">更多>></a></div>
<div class="sub_no" id="bd1lfsj">
<ul>
<li class="show">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
<div id="bd1lfimg">
<div>
<dl class="show">
<dt><a href="#"><img src="images/1.jpg" alt="2011城市主题公园亲子游"></a></dt>
<dd>
<h2><a href="#">2014城市主题公园亲子游</a></h2>
<tt><a href="#">又是春游踏青的季节,各大主题乐园都为大朋友、小朋友们准备了丰…</a></tt>
</dd>
</dl>
<dl>
<dt><a href="#"><img src="images/2.jpg" alt="潜入城市周边清幽之地"></a></dt>
<dd>
<h2><a href="#">潜入城市周边清幽之地</a></h2>
<tt><a href="#">北京、上海、广州、成都周边,总有些人少清幽的地方,等着你去探…</a></tt>
</dd>
</dl>
<dl>
<dt><a href="#"><img src="images/3.jpg" alt="盘点中国最美雪山"></a></dt>
<dd>
<h2><a href="#">盘点中国最美雪山</a></h2>
<tt><a href="#">盘点中国最美雪山,从云南的梅里到西藏的珠穆朗玛,带你领略中国…</a></tt>
</dd>
</dl>
<dl>
<dt><a href="#"><img src="images/4.jpg" alt="2011西安世园会攻略"></a></dt>
<dd>
<h2><a href="#">2011西安世园会攻略</a></h2>
<tt><a href="#">提供最全面西安世园会资讯、西安世园会参观指南、西安世园会旅游…</a></tt>
</dd>
</dl>
<dl>
<dt><a href=" "><img src="images/5.jpg" alt="五月乐享懒人天堂塞班岛"></a></dt>
<dd>
<h2><a href="#">五月乐享懒人天堂塞班岛</a></h2>
<tt><a href="#">塞班岛是北马里亚纳群岛的首府,由于近邻赤道,塞班岛一年四季如…</a></tt>
</dd>
</dl>
</div>
</div>
</div>
<script type="text/javascript">movec();</script>
</body>
</html>
JS代码(focus.js):
//选择器function $a(id,tag){
var re=(id&&typeof id!="string")?id:document.getElementById(id);
if(!tag){
return re;
}
else{
return re.getElementsByTagName(tag);
}
}
//焦点滚动图 点击移动function movec(){
var o=$a("bd1lfimg","");
var oli=$a("bd1lfimg","dl");
var oliw=oli[0].offsetWidth;
//每次移动的宽度var ow=o.offsetWidth-2;
var dnow=0;
//当前位置var olf=oliw-(ow-oliw+10)/2;
o["scrollLeft"]=olf+(dnow*oliw);
var rqbd=$a("bd1lfsj","ul")[0];
var extime;
<!--for(var i=1;
i<oli.length;
i++){
rqbd.innerHTML+="<li>"+i+"</li>";
}
-->var rq=$a("bd1lfsj","li");
for(var i=0;
i<rq.length;
i++){
reg(i);
}
;
oli[dnow].className=rq[dnow].className="show";
var wwww=setInterval(uu,2000);
function reg(i){
rq[i].onclick=function(){
oli[dnow].className=rq[dnow].className="";
dnow=i;
oli[dnow].className=rq[dnow].className="show";
mv();
}
}
function mv(){
clearInterval(extime);
clearInterval(wwww);
extime=setInterval(bc,15);
wwww=setInterval(uu,8000);
}
function bc(){
var ns=((dnow*oliw+olf)-o["scrollLeft"]);
var v=ns>0?Math.ceil(ns/10):Math.floor(ns/10);
o["scrollLeft"]+=v;
if(v==0){
clearInterval(extime);
oli[dnow].className=rq[dnow].className="show";
v=null;
}
}
function uu(){
if(dnow<oli.length-2){
oli[dnow].className=rq[dnow].className="";
dnow++;
oli[dnow].className=rq[dnow].className="show";
}
else{
oli[dnow].className=rq[dnow].className="";
dnow=0;
oli[dnow].className=rq[dnow].className="show";
}
mv();
}
o.onmouseover=function(){
clearInterval(extime);
clearInterval(wwww);
}
o.onmouseout=function(){
extime=setInterval(bc,15);
wwww=setInterval(uu,8000);
}
}
CSS代码(style.css):
@charset "utf-8";*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
body{font:12px/180% Arial,Helvetica,sans-serif,"新宋体";}
a{text-decoration:none;color:#434343;}
a:hover{text-decoration:underline;color:#ff4000;}
/* sub_box */
.sub_box{width:663px;height:310px;margin:40px auto 0 auto;position:relative;overflow:hidden;border:1px solid #ccc;}
.sub_box img{width:663px;height:310px;}
#bd1lfimg{position:relative;width:663px;height:310px;overflow:hidden;}
#bd1lfimg div{width:100000px;margin-left:659px;}
#bd1lfimg dl{width:663px;height:310px;position:relative;overflow:hidden;float:left;}
#bd1lfimg dt{width:663px;height:310px;position:absolute;left:0px;top:0px;}
#bd1lfimg dd{width:623px;height:80px;background:#000000;filter:alpha(Opacity=70);Opacity:0.7;position:absolute;left:0px;bottom:0px;padding:0 20px;}
#bd1lfimg dd h2{height:25px;padding:8px 0 4px 0;line-height:25px;overflow:hidden;}
#bd1lfimg dd h2 a{font-size:14px;font-weight:bold;color:#ffffff;}
#bd1lfimg dd a{color:#ffffff;text-decoration:none;}
#bd1lfimg dd a:hover{text-decoration:none;color:#cccccc;}
#bd1lfimg dd tt{color:#dddddd;line-height:1.2em;}
#bd1lfimg dd tt a:hover{text-decoration:underline;}
.sub_nav{width:663px;height:25px;bottom:0px;position:absolute;color:#999999;z-index:200;}
.sub_no{height:25px;float:right;}
.sub_no li{display:block;width:25px;height:25px;float:left;overflow:hidden;line-height:25px;vertical-align:middle;text-align:center;background:#000000;filter:alpha(Opacity=70);Opacity:0.7;font-family:Arial;font-size:11px;color:#999999;cursor:pointer;}
.sub_no li.show{background:#ffffff;color:#000000;}
.sub_more{float:right;width:50px;height:25px;background:#000000;filter:alpha(Opacity=70);Opacity:0.7;color:#999999;text-align:center;line-height:25px;}
.sub_more a{color:#999999;}
.sub_more a:hover{color:#cccccc;text-decoration:none;}