<!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">
<!--把下面代码加到<head>与</head>之间-->
<script language="javascript">
//声明命名空间
var $o = new Object();
//基础方法
$o.base = {
e:function(a,f){
for(var i=0,j=a.length;i<j;i++){f.call(a[i],i);}
}
}
$o. slide = function (id,arg){
var arg = arg||{},
t = document.getElementById(id),
a = t.getElementsByTagName("a"),
lis = [],
cl = arg.color||'#f30',
ctm = arg.time*1000||2000,
w = t.clientWidth,
h = t.clientHeight,
b = ['<ul style="margin:0; padding:0; list-style:none; display:block; position:absolute; bottom:10px; right:10px;">'],
index = 0,
$ = null,
$ = null;
function change(i){
if(!!$){clearTimeout($);}
index = !isNaN(i)?i:index+1;
if(index >= a.length){index = 0;}
$o.base.e(lis,function(k){if(k == index){c(1,this);}else{c(0,this)}});
var to = - index*h;
if(a[0].offsetTop == to){
return;
}else{
if(!!$){clearInterval($);}
$ = setInterval(function(){
var ot = a[0].offsetTop;
v = Math[to<ot?'floor':'ceil']((to - ot)*0.2);
if(ot == to){clearInterval($);$=null;st();}
ot += v;
a[0].style.marginTop = ot + "px";
},30)
};
}
function c(b,o){
o.style.backgroundColor = !!b?cl:"#fff";
o.style.color = !!b?"#fff":cl;
}
function st(){
if(!!$)clearTimeout($);
$ = setTimeout(function(){change()},ctm);
}
with(t.style){overflow = 'hidden';position = 'relative';}
$o.base.e(a,function(n){
this.style.display = "block";
with(this.firstChild.style){borderWidth = '0';width = w + 'px';height = h + 'px';}
b.push('<li style="width:20px; height:20px; line-height:20px; display:block; float:left; margin-left:5px; border:1px solid ' + cl + '; background-color:#fff; color:' + cl +'; font-size:14px; text-align:center; cursor:pointer;">' + (n+1) + '</li>');
});
b.push('</ul>');
t.innerHTML += b.join("");
lis = t.getElementsByTagName("li");
$o.base.e(lis,function(n){
if(n == index){c(1,this)}
this.onmouseover = function(){
if(n!=index)change(n);
}
});
st();
}
</script>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<div id="aa" style="width:402px;height:228px;">
<a href="javascript:alert('1')"><img src="/images/1.jpg"></a>
<a href="javascript:alert('2')"><img src="/images/2.jpg"></a>
<a href="javascript:alert('3')"><img src="/images/3.jpg"></a>
<a href="javascript:alert('4')"><img src="/images/4.jpg"></a>
<a href="javascript:alert('5')"><img src="/images/5.jpg"></a>
<a href="javascript:alert('6')"><img src="/images/6.jpg"></a>
<a href="javascript:alert('7')"><img src="/images/7.jpg"></a>
<a href="javascript:alert('8')"><img src="/images/8.jpg"></a>
<a href="javascript:alert('9')"><img src="/images/9.jpg"></a>
</div>
<script language="javascript">
new $o.slide("aa");
</script>
<br>
<div id="bb" style="width:402px;height:228px;">
<a href="###"><img src="/images/1.jpg"></a>
<a href="###"><img src="/images/2.jpg"></a>
<a href="###"><img src="/images/3.jpg"></a>
<a href="###"><img src="/images/4.jpg"></a>
<a href="###"><img src="/images/5.jpg"></a>
</div>
<script language="javascript">
new $o.slide("bb",{color:'#000',time:0.2});
</script>
<br>
<div id="cc" style="width:402px;height:228px;">
<a href="###"><img src="/images/1.jpg"></a>
<a href="###"><img src="/images/2.jpg"></a>
<a href="###"><img src="/images/3.jpg"></a>
<a href="###"><img src="/images/4.jpg"></a>
<a href="###"><img src="/images/5.jpg"></a>
</div>
<script language="javascript">
new $o.slide("cc",{color:'green'});
</script>
</body>
</html>

最新文章

  1. html5 formData上传 针对app端
  2. nohup命令浅析
  3. 【转】你真的了解word-wrap和word-break的区别吗?
  4. datepicker自定义 -- iOS
  5. 利用DBCC PAGE查看SQL Server中的表和索引数据
  6. Notice: Undefined offset 的解决方法
  7. 在Tomcat下配置Solr 4.x 版本
  8. c# winfrom应用程序关闭任务管理器中的进程
  9. 大数据时代下的用户洞察:用户画像建立(ppt版)
  10. 算法打基础——HashTable
  11. 1901: Zju2112 Dynamic Rankings
  12. PHP获取指定页面的指定内容
  13. [刷题]算法竞赛入门经典 3-10/UVa1587 3-11/UVa1588
  14. 疑难杂症——关于EntityFramework的SqlQuery方法的执行效率差异的探讨
  15. &#183;通过wifi_scan学习esp32wifi程序编写
  16. 学机器学习,不会数据处理怎么行?—— 一、NumPy详解
  17. Row_number 详解
  18. C++复习:STL之算法
  19. Log4cplus使用指南
  20. 【RF库Collections测试】Sort List

热门文章

  1. as3中使用stage ,root ,this 区别详解
  2. mysql并发复制系列 一:binlog组提交
  3. 描述cookie,sessionstroage,localstrage的区别
  4. mysql中使用count()统计的特殊之处
  5. PHP设计模式之策略模式
  6. cocos2dx 背景用小尺寸图片滚动填充的方法
  7. Linux shell 脚本攻略之根据扩展名切分文件名
  8. 关于 error: LNK1123: failure during conversion to COFF: file invalid or corrupt 错误的解决方案【Qt】【 VS2010】
  9. poj1068解题报告(模拟类)
  10. jquery ajax 后台和前台数据交互 C#