打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
NBA网站的大幅焦点图切换效果,代码里有较多的注释,适合研究一下,图片是远程地址,你最好保存到本地,本焦点图是动态变化,会自动播放,鼠标点击的时候会响应鼠标,用JavaScript实现的。
前后轮翻的JS图片幻灯切换,和普通的图片切换没有什么区别,区别在于图片的切换方式上,用到了一些prototype的相关技术,自动检测图片张数,运行时如果看不到效果,请等待图片加载完成。
 
<!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>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
通过map热点实现鼠标点击弹出div的效果
超酷JS拖拽翻页效果.htm
又一个做网站比较流行的图片幻灯片网页特效
默识| 博客模板布局的基本知识
xwhyc的tw2过滤规则(2011年04月05日更新)
【博客】动态鼠标样式代码
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服