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

代码简介:

前后轮翻的JS图片幻灯切换,和普通的图片切换没有什么区别,区别在于图片的切换方式上,用到了一些prototype的相关技术,自动检测图片张数,运行时如果看不到效果,请等待图片加载完成。

代码内容:

View Code
<!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图片幻灯切换代码_网页代码站(www.webdm.cn)</title>
<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="http://www.webdm.cn/images/wall1.jpg"></a>
    <a href=
"#" id="banner_up_2" style="z-index:3"><img src="http://www.webdm.cn/images/wall2.jpg"></a>
    <a href=
"#" id="banner_up_3" style="z-index:2"><img src="http://www.webdm.cn/images/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>
<br />
<p><a href=
"http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p>
代码来自:
http://www.webdm.cn/webcode/5a5b3625-2e52-4520-a21f-ec06db5d5194.html

 

 

posted @ 2011-08-06 10:03  网页代码站  阅读(339)  评论(0编辑  收藏  举报