前后轮翻的JS图片幻灯切换

来源:互联网 发布:算法时间复杂度分析 编辑:程序博客网 时间:2024/04/29 11:53
<!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>
<title>前后轮翻的JS图片幻灯切换</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
img{border:0;}
.bannerImage{margin-left:200px;margin-top:50px;border:1px solid #f60;width:452px;height:346px;position:relative; overflow:hidden;}
.bannerImage p{font-size:0;display:block;width:448px;height:338px;}
.bannerImage p a{position:absolute;left:0px;top:0px;}
.bannerImage span{position:absolute; right:10px;bottom:10px; z-index:100;}
.bannerImage span a{text-decoration:none; margin-left:5px; display:block;border:1px solid #f60; text-align:center;width:14px; height:16px; background-color:#fff;float:left; font-size:12px; background-color:#999;}
.bannerImage span a:hover{background-color:#eee;}
.bannerImage span a.cur{background-color:#eee;}
.hid{display:none;}
</style>
<script type="text/javascript">
var $ID = function(id){
return "string"==typeof id?document.getElementById(id):id;
}
var Class = {
create:function(){
return function(){
this.initilize.apply(this,arguments);
}
}
}
var Bind = function(object,fun){
var args = Array.prototype.slice.call(arguments,2);
return function(){
return fun.apply(object,args);
}
}
</script>
<script type="text/javascript">
var Flash = Class.create();
Flash.prototype = {
initilize:function(contain){
this.len = $ID(contain).getElementsByTagName("p")[0].getElementsByTagName("a").length;
if(this.len<=1) return;
this.width = $ID("banner_up_1").offsetWidth;
this.cur = 1;
if(this.len<=1) return;
this.cur2 = 2;
this.i = 0;
this._fnRun = Bind(this,this.Run);
this._fnRun2 = Bind(this,this.Run2);
this.t = window.setTimeout(this._fnRun,2000);
},
Run:function(){
if(this.i<=-(this.width/2)){
this.i = -(this.width/2)
$ID("banner_up_" + this.cur).style.left = this.i + "px";
$ID("banner_up_" + this.cur2).style.left = -this.i + "px";
$ID("banner_up_" + this.cur2).style.zIndex = parseInt($ID("banner_up_" + this.cur).style.zIndex) + this.len;
this.t = window.setTimeout(this._fnRun2,5);
return;
}
this.i-=6;
$ID("banner_up_" + this.cur).style.left = this.i + "px";
$ID("banner_up_" + this.cur2).style.left = Math.abs(this.i) + "px";
this.t = window.setTimeout(this._fnRun,10);
},
Run2:function(){
if(this.i>0){
$ID("banner_down_" + this.cur).className = "";
$ID("banner_down_" + this.cur2).className = "cur";
$ID("banner_up_" + this.cur).style.left = $ID("banner_up_" + this.cur2).style.left = "0px";
this.cur++;
if(this.cur>this.len)
this.cur = 1;
this.cur2 = this.GetNext();
$ID("banner_up_" + this.cur2).style.zIndex = parseInt($ID("banner_up_" + this.cur).style.zIndex)-1;
this.t = window.setTimeout(this._fnRun,3000);
return;
}
this.i+=6;
$ID("banner_up_" + this.cur).style.left = this.i + "px";
$ID("banner_up_" + this.cur2).style.left = -this.i + "px";
this.t = window.setTimeout(this._fnRun2,10);
},
GetNext:function(){
if(this.cur == this.len)
return 1;
else
return this.cur + 1;
}
}
onload = function(){
new Flash("bannerImage");
}
</script>
</head>
<body>
<div class="bannerImage" id="bannerImage">
  <p>
    <a href="#" id="banner_up_1" style="z-index:4"><img src="wall1.jpg"></a>
    <a href="#" id="banner_up_2" style="z-index:3"><img src="wall2.jpg"></a>
    <a href="#" id="banner_up_3" style="z-index:2"><img src="wall3.jpg"></a>
  </p>
  <span>
    <a href="#" id="banner_down_1" class="cur">1</a>
    <a href="#" id="banner_down_2">2</a>
    <a href="#" id="banner_down_3">3</a>
  </span>
</div>
</body>
</html>
0 0
原创粉丝点击