JS图片滚动代码(无缝、平滑)

<!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="/jscss/demoimg/wall1.jpg"></a>
    <a href="#" id="banner_up_2" style="z-index:3"><img src="/jscss/demoimg/wall2.jpg"></a>
    <a href="#" id="banner_up_3" style="z-index:2"><img src="/jscss/demoimg/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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值