前后轮翻的JS图片幻灯切换
2016-07-11 11:26
579 查看
<!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>
<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>
相关文章推荐
- C# winsocket连接 Jsonp
- 马赛克效果的JS图片切换代码
- 亮丽的JS图片渐变导航
- JSP获取绝对路径
- Js运动动画系列4--多物体缓冲运动
- 规定区域的JS拖动展示效果
- JS闭包学习笔记(3):模块
- Js运动动画系列3--缓冲运动
- 从两侧向中间拼合的JavaScript图片切换效果
- 大幅JS焦点图切换
- 按比例缩放图片,JavaScript代码
- js中函数表达式和函数声明
- jsp与servlet传值相关问题
- Js拖动特效,一串水晶球(很强大)
- Js图片连续左右滚动
- JS图片切换,带缩略图版
- JS卡通图片切换
- JS图片滚动代码(无缝、平滑)
- 史上最全、JavaScript基础篇
- JS点击小图预览大图(仿淘宝)