javascript实现图片轮换动作方法

时间:2021-10-20 15:12:12

图片轮换是一种相当复杂的技术,早些年基本用flash实现。这里有一个链接,教大家如何用flash实现它的。之所以用flash,是因为flash是基于帧的,这与图片轮换的原理相当接近。为了模拟帧的效果,我们要用到overflow把多余的部分遮罩掉,也就是flash中常说的遮罩层。在Flash中,连时间轴都是可视的,而我们则全凭想象力与数学来计算现在是到了哪一张图。加之,flash有Robert Penner大神的缓动公式,那实在太耀眼,直到script.aculo.us类库搞出自己的缓动公式,才扭转局面。

我们来看一看图片轮换的结构层。它应该包含框体,图片展示区,图片滑动层与分页栏。原谅我制造这么多词汇,因为没有个名词讲解就难以为继了,前人也没有做这样的总结,个个都不愿意分享一下。框体就是一个div元素,作用有两个:提供相册的边框与作为分页栏的包含块。如果不清楚什么叫包含块(containing block)的话,自己查阅CSS权威指南吧。接着下来图片展示区与图片滑动层,也就是我实现新式无缝滚动的那一种结构,一个很干净的无序列表,所有难点都转移到设置它的CSS上。至于图片展示区就是ul元素,大小为一张图片的大小;图片滑动层就是那个li元素,也只有一个li元素而已,利用CSS强制把它里面的图片不换行向左浮动,并设置li元素一个很大很大的宽度,好让它一行容纳所有图片。分页栏就是一个包含许多链接的span元素,和普通的水平菜单差不多,只不过要用绝对定位它安置到框体的右下角。

  1. <div id="album"
  2.  <ul> 
  3.  <li> 
  4.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index1"
  5.   <img alt="月光下的花瓣" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg" /> 
  6.   </a> 
  7.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index2"
  8.   <img alt="清澈的湖水" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s002.jpg" /> 
  9.   </a> 
  10.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index3"
  11.   <img alt="荒漠上的植物" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s003.jpg" /> 
  12.   </a> 
  13.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index4"
  14.   <img alt="末日霓虹" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s004.jpg" /> 
  15.   </a> 
  16.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index5"
  17.   <img alt="绿·生意" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s005.jpg" /> 
  18.   </a> 
  19.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index6"
  20.   <img alt="又是收获的季节" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s006.jpg" /> 
  21.   </a> 
  22.  </li> 
  23.  </ul> 
  24.  <span> 
  25.  <a href="#index1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a> 
  26.  <a href="#index2" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a> 
  27.  <a href="#index3" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a> 
  28.  <a href="#index4" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a> 
  29.  <a href="#index5" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a> 
  30.  <a href="#index6" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6</a> 
  31.  </span> 
  32. </div> 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#album {
 position:relative;/*为分页栏准备的*/
 width:400px;/*必须设置,为分页栏准备*/
 height:300px;/*必须设置,为分页栏准备*/
 border:10px solid #8080C0;
}
#album ul ,#album li {/*消除默认样式*/
 padding:0;
 margin:0;
 list-style:none;
}
#album ul{
 position:relative; /*为图片滑动区*/
 height:300px;/*必须设置,用于隐藏图片滑动区多余的部分*/
 width:400px;/*必须设置,用于隐藏图片滑动区多余的部分*/
 overflow:hidden;
 background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg) no-repeat 0 0;
}
#album li { /*图片滑动区*/
 position:absolute;
 width:1000%;/*让里面的所有图片并列显示*/
}
#album a {
 float:left;
}
#album img {
 display:block;
 border:0;
}
#album span {/*分页栏*/
 position:absolute;
 right:0;
 bottom:10px;
}
#album span a{
 display:block;/*让其拥有盒子模型*/
 margin-right:10px;/*错开格子*/
 width:15px;/*呈正方形*/
 height:15px;
 line-height:15px;
 text-align:center;/*居中显示*/
 text-decoration:none;/*消除下划线*/
 color:#808080;
 background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_button.gif) no-repeat -15px 0;
}
#album span a:hover ,#album span a.hover{
 color:#F8F8F8;
 background-position:0 0;
}
  1. <!doctype html> 
  2. <title>javascript图片轮换 by 司徒正美</title> 
  3. <meta charset="utf-8"/> 
  4. <meta name="keywords" content="javascript图片轮换 by 司徒正美" /> 
  5. <meta name="description" content="javascript图片轮换 by 司徒正美" /> 
  6. <style type="text/css"
  7.  #album { 
  8.  position:relative;/*为分页栏准备的*/ 
  9.  width:400px;/*必须设置,为分页栏准备*/ 
  10.  height:300px;/*必须设置,为分页栏准备*/ 
  11.  border:10px solid #8080C0; 
  12.  } 
  13.  #album ul ,#album li {/*消除默认样式*/ 
  14.  padding:0; 
  15.  margin:0; 
  16.  list-style:none; 
  17.  } 
  18.  #album ul{ 
  19.  position:relative; /*为图片滑动区*/ 
  20.  height:300px;/*必须设置,用于隐藏图片滑动区多余的部分*/ 
  21.  width:400px;/*必须设置,用于隐藏图片滑动区多余的部分*/ 
  22.  overflow:hidden; 
  23.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg) no-repeat 0 0; 
  24.  } 
  25.  #album li { /*图片滑动区*/ 
  26.  position:absolute; 
  27.  width:1000%;/*让里面的所有图片并列显示*/ 
  28.  } 
  29.  #album a { 
  30.  float:left; 
  31.  } 
  32.  #album img { 
  33.  display:block; 
  34.  border:0; 
  35.  } 
  36.  #album span {/*分页栏*/ 
  37.  position:absolute; 
  38.  right:0; 
  39.  bottom:10px; 
  40.  } 
  41.  #album span a{ 
  42.  display:block;/*让其拥有盒子模型*/ 
  43.  margin-right:10px;/*错开格子*/ 
  44.  width:15px;/*呈正方形*/ 
  45.  height:15px; 
  46.  line-height:15px; 
  47.  text-align:center;/*居中显示*/ 
  48.  text-decoration:none;/*消除下划线*/ 
  49.  color:#808080; 
  50.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_button.gif) no-repeat -15px 0; 
  51.  } 
  52.  #album span a:hover ,#album span a.hover{ 
  53.  color:#F8F8F8; 
  54.  background-position:0 0; 
  55.  } 
  56. </style> 
  57. <h4>javascript图片轮换 by 司徒正美</h4> 
  58. <div id="album"
  59.  <ul> 
  60.  <li> 
  61.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index1"
  62.   <img alt="月光下的花瓣" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg" /> 
  63.   </a> 
  64.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index2"
  65.   <img alt="清澈的湖水" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s002.jpg" /> 
  66.   </a> 
  67.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index3"
  68.   <img alt="荒漠上的植物" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s003.jpg" /> 
  69.   </a> 
  70.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index4"
  71.   <img alt="末日霓虹" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s004.jpg" /> 
  72.   </a> 
  73.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index5"
  74.   <img alt="绿·生意" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s005.jpg" /> 
  75.   </a> 
  76.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index6"
  77.   <img alt="又是收获的季节" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s006.jpg" /> 
  78.   </a> 
  79.  </li> 
  80.  </ul> 
  81.  <span> 
  82.  <a href="#index1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a> 
  83.  <a href="#index2" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a> 
  84.  <a href="#index3" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a> 
  85.  <a href="#index4" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a> 
  86.  <a href="#index5" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a> 
  87.  <a href="#index6" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6</a> 
  88.  </span> 
  89. </div> 

这个和我以前的系列一样,不用JS也可以点击实现切换。不过以前是用锚点来改变scrollTop的值,现在是改变scrollLeft的值。

如果不使用缓动效果,很简单。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var Rotate = function(id){
 try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
 var container = document.getElementById(id),
 slide = container.getElementsByTagName("li")[0];
 slide.innerHTML += slide.innerHTML;
 var item = slide.getElementsByTagName("a"),
 critical = item[item.length/2].offsetLeft,//临界值
 distance = critical/(item.length/2),
 delta = - distance;
 (function(){//实现自动轮换图片
 setTimeout(function(){
  delta = delta - distance;
  if(delta < -critical){
  delta = - distance;
  }
  slide.style.left = delta + "px";//★★★★★★★★
  setTimeout(arguments.callee,1500)
 },1500)
 })()
}

要使用缓动,就要动用我的缓动公式与transition函数,在星号的位置中调用。

  1. <!doctype html> 
  2. <title>javascript图片轮换 by 司徒正美</title> 
  3. <meta charset="utf-8"/> 
  4. <meta name="keywords" content="javascript图片轮换 by 司徒正美" /> 
  5. <meta name="description" content="javascript图片轮换 by 司徒正美" /> 
  6. <style type="text/css"
  7.  #album { 
  8.  position:relative; 
  9.  width:400px; 
  10.  height:300px; 
  11.  border:10px solid #8080C0; 
  12.  } 
  13.  
  14.  #album ul,#album li { 
  15.  list-style:none; 
  16.  margin:0; 
  17.  padding:0; 
  18.  } 
  19.  
  20.  #album ul { 
  21.  position:relative; 
  22.  height:300px; 
  23.  width:400px; 
  24.  overflow:hidden; 
  25.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg) no-repeat 0 0; 
  26.  } 
  27.  
  28.  #album li { 
  29.  position:absolute; 
  30.  width:1000%; 
  31.  } 
  32.  
  33.  #album a { 
  34.  float:left; 
  35.  } 
  36.  
  37.  #album img { 
  38.  display:block; 
  39.  border:0; 
  40.  } 
  41.  
  42.  #album span { 
  43.  position:absolute; 
  44.  right:0; 
  45.  bottom:10px; 
  46.  } 
  47.  
  48.  #album span a { 
  49.  display:block; 
  50.  margin-right:10px; 
  51.  width:15px; 
  52.  height:15px; 
  53.  line-height:15px; 
  54.  text-align:center; 
  55.  text-decoration:none; 
  56.  color:gray; 
  57.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_button.gif) no-repeat -15px 0; 
  58.  } 
  59.  
  60.  #album span a:hover,#album span a.hover { 
  61.  color:#F8F8F8; 
  62.  background-position:0 0; 
  63.  } 
  64. </style> 
  65. <script type="text/javascript"
  66.  var spring= function(pos) { 
  67.  return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6)); 
  68.  } 
  69.  var transition = function(el){ 
  70.  var options = arguments[1] || {}, 
  71.  begin = options.begin,//开始位置 
  72.  change = options.change,//变化量 
  73.  duration = options.duration || 500,//缓动效果持续时间 
  74.  ftp = options.ftp || 50, 
  75.  onEnd = options.onEnd || function(){}, 
  76.  ease = options.ease,//要使用的缓动公式 
  77.  end = begin + change,//结束位置 
  78.  startTime = new Date().getTime();//开始执行的时间 
  79.  (function(){ 
  80.   setTimeout(function(){ 
  81.   var newTime = new Date().getTime(),//当前帧开始的时间 
  82.   timestamp = newTime - startTime,//逝去时间 
  83.   delta = ease(timestamp / duration); 
  84.   el.style.left = Math.ceil(begin + delta * change) + "px" 
  85.   if(duration <= timestamp){ 
  86.    el.style.left = end + "px"
  87.    onEnd(); 
  88.   }else
  89.    setTimeout(arguments.callee,1000/ftp); 
  90.   } 
  91.   },1000/ftp) 
  92.  })() 
  93.  } 
  94.  var Rotate = function(id){ 
  95.  try{document.execCommand("BackgroundImageCache"falsetrue);}catch(e){}; 
  96.  var container = document.getElementById(id), 
  97.  slide = container.getElementsByTagName("li")[0], 
  98.  paginater = container.getElementsByTagName("span")[0], 
  99.  links = paginater.getElementsByTagName("a"), 
  100.  length = links.length, aBefore = length, aIndex; 
  101.  slide.innerHTML += slide.innerHTML; 
  102.  var item = slide.getElementsByTagName("a"), 
  103.  critical = item[length].offsetLeft,//临界值 
  104.  distance = critical/length, 
  105.  delta = - distance; 
  106.  (function(){//实现自动轮换图片 
  107.   setTimeout(function(){ 
  108.   delta = delta - distance; 
  109.   if(delta < -critical){ 
  110.    delta = - distance; 
  111.   } 
  112.   aIndex = - delta/distance; 
  113.   links[aBefore-1].className = ""
  114.   links[aIndex-1].className = "hover"
  115.   aBefore = aIndex; 
  116.   transition(slide,{begin:delta,change:distance,ease:spring}) 
  117.   setTimeout(arguments.callee,1500) 
  118.   },1500) 
  119.  })() 
  120.  } 
  121.  window.onload = function(){ 
  122.  Rotate("album"); 
  123.  } 
  124. </script> 
  125. <h4>javascript图片轮换 by 司徒正美</h4> 
  126. <div id="album"
  127.  <ul> 
  128.  <li> 
  129.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index1"
  130.   <img alt="月光下的花瓣" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg" /> 
  131.   </a> 
  132.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index2"
  133.   <img alt="清澈的湖水" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s002.jpg" /> 
  134.   </a> 
  135.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index3"
  136.   <img alt="荒漠上的植物" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s003.jpg" /> 
  137.   </a> 
  138.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index4"
  139.   <img alt="末日霓虹" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s004.jpg" /> 
  140.   </a> 
  141.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index5"
  142.   <img alt="绿·生意" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s005.jpg" /> 
  143.   </a> 
  144.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index6"
  145.   <img alt="又是收获的季节" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s006.jpg" /> 
  146.   </a> 
  147.  </li> 
  148.  </ul> 
  149.  <span> 
  150.  <a href="#index1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a> 
  151.  <a href="#index2" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a> 
  152.  <a href="#index3" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a> 
  153.  <a href="#index4" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a> 
  154.  <a href="#index5" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a> 
  155.  <a href="#index6" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6</a> 
  156.  </span> 
  157. </div> 

我们也可以像第一部分那样加入一个信息栏,这样程序就拥有三个定时器了,看起来让人有点头晕,现实中不提倡这样做,这里只是试范一下如何使用transition的回调函数罢了。

?
1
2
3
4
5
6
7
8
9
//动态生成li元素并把它插入到DOM树中。
var tip = document.createElement("li");//信息栏
tip.style.cssText = "position:absolute;bottom:0;width:400px;height:40px;line-height:40px;text-indent:2em;";
slide.parentNode.appendChild(tip);
if(!+"1"){
 tip.style.cssText += "color:#369;background:#fff;filter:alpha(opacity=50)";
}else{
 tip.style.cssText += "color:#fff;background: rgba(164, 173, 183, .65);";
}
 
  1. <!doctype html> 
  2. <title>javascript图片轮换 by 司徒正美</title> 
  3. <meta charset="utf-8"/> 
  4. <meta name="keywords" content="javascript图片轮换 by 司徒正美" /> 
  5. <meta name="description" content="javascript图片轮换 by 司徒正美" /> 
  6. <style type="text/css"
  7.  #album { 
  8.  position:relative; 
  9.  width:400px; 
  10.  height:300px; 
  11.  border:10px solid #8080C0; 
  12.  } 
  13.  
  14.  #album ul,#album li { 
  15.  list-style:none; 
  16.  margin:0; 
  17.  padding:0; 
  18.  } 
  19.  
  20.  #album ul { 
  21.  position:relative; 
  22.  height:300px; 
  23.  width:400px; 
  24.  overflow:hidden; 
  25.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg) no-repeat 0 0; 
  26.  } 
  27.  
  28.  #album li { 
  29.  position:absolute; 
  30.  width:1000%; 
  31.  } 
  32.  
  33.  #album a { 
  34.  float:left; 
  35.  } 
  36.  
  37.  #album img { 
  38.  display:block; 
  39.  border:0; 
  40.  } 
  41.  
  42.  #album span { 
  43.  position:absolute; 
  44.  right:0; 
  45.  bottom:10px; 
  46.  } 
  47.  
  48.  #album span a { 
  49.  display:block; 
  50.  margin-right:10px; 
  51.  width:15px; 
  52.  height:15px; 
  53.  line-height:15px; 
  54.  text-align:center; 
  55.  text-decoration:none; 
  56.  color:gray; 
  57.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_button.gif) no-repeat -15px 0; 
  58.  } 
  59.  
  60.  #album span a:hover,#album span a.hover { 
  61.  color:#F8F8F8; 
  62.  background-position:0 0; 
  63.  } 
  64. </style> 
  65. <script type="text/javascript"
  66.  var easeInOutCubic= function(pos){ 
  67.  if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,3); 
  68.  return 0.5 * (Math.pow((pos-2),3) + 2); 
  69.  } 
  70.  
  71.  var transition = function(el){ 
  72.  var options = arguments[1] || {}, 
  73.  begin = options.begin,//开始位置 
  74.  change = options.change,//变化量 
  75.  duration = options.duration || 500,//缓动效果持续时间 
  76.  ftp = options.ftp || 50, 
  77.  onEnd = options.onEnd || function(){}, 
  78.  ease = options.ease,//要使用的缓动公式 
  79.  end = begin + change,//结束位置 
  80.  startTime = new Date().getTime();//开始执行的时间 
  81.  (function(){ 
  82.   setTimeout(function(){ 
  83.   var newTime = new Date().getTime(),//当前帧开始的时间 
  84.   timestamp = newTime - startTime,//逝去时间 
  85.   delta = ease(timestamp / duration); 
  86.   el.style.left = Math.ceil(begin + delta * change) + "px" 
  87.   if(duration <= timestamp){ 
  88.    el.style.left = end + "px"
  89.    onEnd(); 
  90.   }else
  91.    setTimeout(arguments.callee,1000/ftp); 
  92.   } 
  93.   },1000/ftp) 
  94.  })() 
  95.  } 
  96.  var Rotate = function(id){ 
  97.  try{document.execCommand("BackgroundImageCache"falsetrue);}catch(e){}; 
  98.  var container = document.getElementById(id), 
  99.  slide = container.getElementsByTagName("li")[0], 
  100.  paginater = container.getElementsByTagName("span")[0], 
  101.  links = paginater.getElementsByTagName("a"), 
  102.  images = slide.getElementsByTagName("img"), 
  103.  length = links.length, aBefore = length, aIndex; 
  104.  slide.innerHTML += slide.innerHTML; 
  105.  var tip = document.createElement("li"); 
  106.  tip.style.cssText = "position:absolute;bottom:-40px;height:20px;width:380px;padding:10px;color:#fff;background:#fff;"
  107.  slide.parentNode.appendChild(tip); 
  108.  if(!+"1"){ 
  109.   tip.style.color = "#369"
  110.   tip.style.filter = "alpha(opacity=67)" 
  111.  }else
  112.   tip.style.cssText += "background: rgba(164, 173, 183, .65);" 
  113.  } 
  114.  var item = slide.getElementsByTagName("a"), 
  115.  critical = item[length].offsetLeft,//临界值 
  116.  distance = critical/length, 
  117.  delta = - distance; 
  118.  (function(){//实现自动轮换图片 
  119.   setTimeout(function(){ 
  120.   delta = delta - distance; 
  121.   if(delta < -critical){ 
  122.    delta = - distance; 
  123.   } 
  124.   aIndex = - delta/distance; 
  125.   tip.innerHTML = images[aIndex-1].getAttribute("alt"); 
  126.   tip.style.bottom = "-40px"
  127.   links[aBefore-1].className = ""
  128.   links[aIndex-1].className = "hover"
  129.   aBefore = aIndex; 
  130.   transition(slide,{begin:delta,change:distance,ease:easeInOutCubic,onEnd:function(){ 
  131.    move(tip); 
  132.   }}) 
  133.   setTimeout(arguments.callee,2000) 
  134.   },2000) 
  135.  })() 
  136.  } 
  137.  var move = function(el){ 
  138.  var begin = parseFloat(el.style.bottom),speed = 1; 
  139.  el.bottom = begin; 
  140.  (function(){ 
  141.   setTimeout(function(){ 
  142.   el.style.bottom = el.bottom + speed + "px";//移动 
  143.   el.bottom += speed; 
  144.   speed *= 1.5;//下一次移动的距离 
  145.   if(el.bottom >= 0){ 
  146.    el.style.bottom = "0px"
  147.   }else
  148.    setTimeout(arguments.callee,25);//每移动一次停留25毫秒 
  149.   } 
  150.   },25) 
  151.  })() 
  152.  } 
  153.  window.onload = function(){ 
  154.  Rotate("album"); 
  155.  } 
  156. </script> 
  157. <h4>javascript图片轮换 by 司徒正美</h4> 
  158. <div id="album"
  159.  <ul> 
  160.  <li> 
  161.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index1"
  162.   <img alt="月光下的花瓣" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg" /> 
  163.   </a> 
  164.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index2"
  165.   <img alt="清澈的湖水" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s002.jpg" /> 
  166.   </a> 
  167.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index3"
  168.   <img alt="荒漠上的植物" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s003.jpg" /> 
  169.   </a> 
  170.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index4"
  171.   <img alt="末日霓虹" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s004.jpg" /> 
  172.   </a> 
  173.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index5"
  174.   <img alt="绿·生意" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s005.jpg" /> 
  175.   </a> 
  176.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index6"
  177.   <img alt="又是收获的季节" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s006.jpg" /> 
  178.   </a> 
  179.  </li> 
  180.  </ul> 
  181.  <span> 
  182.  <a href="#index1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a> 
  183.  <a href="#index2" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a> 
  184.  <a href="#index3" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a> 
  185.  <a href="#index4" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a> 
  186.  <a href="#index5" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a> 
  187.  <a href="#index6" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6</a> 
  188.  </span> 
  189. </div> 
最后为信息栏上的按钮绑定点击事件就行了。
  1. <!doctype html> 
  2. <title>javascript图片轮换 by 司徒正美</title> 
  3. <meta charset="utf-8"/> 
  4. <meta name="keywords" content="javascript图片轮换 by 司徒正美" /> 
  5. <meta name="description" content="javascript图片轮换 by 司徒正美" /> 
  6. <style type="text/css"
  7.  #album { 
  8.  position:relative; 
  9.  width:400px; 
  10.  height:300px; 
  11.  border:10px solid #8080C0; 
  12.  } 
  13.  
  14.  #album ul,#album li { 
  15.  list-style:none; 
  16.  margin:0; 
  17.  padding:0; 
  18.  } 
  19.  
  20.  #album ul { 
  21.  position:relative; 
  22.  height:300px; 
  23.  width:400px; 
  24.  overflow:hidden; 
  25.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg) no-repeat 0 0; 
  26.  } 
  27.  
  28.  #album li { 
  29.  position:absolute; 
  30.  width:1000%; 
  31.  } 
  32.  
  33.  #album a { 
  34.  float:left; 
  35.  } 
  36.  
  37.  #album img { 
  38.  display:block; 
  39.  border:0; 
  40.  } 
  41.  
  42.  #album span { 
  43.  position:absolute; 
  44.  right:0; 
  45.  bottom:10px; 
  46.  } 
  47.  
  48.  #album span a { 
  49.  display:block; 
  50.  margin-right:10px; 
  51.  width:15px; 
  52.  height:15px; 
  53.  line-height:15px; 
  54.  text-align:center; 
  55.  text-decoration:none; 
  56.  color:gray; 
  57.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_button.gif) no-repeat -15px 0; 
  58.  } 
  59.  
  60.  #album span a:hover,#album span a.hover { 
  61.  color:#F8F8F8; 
  62.  background-position:0 0; 
  63.  } 
  64. </style> 
  65. <script type="text/javascript"
  66.  var easeInOutCubic= function(pos){ 
  67.  if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,3); 
  68.  return 0.5 * (Math.pow((pos-2),3) + 2); 
  69.  } 
  70.  
  71.  var transition = function(el){ 
  72.  var options = arguments[1] || {}, 
  73.  begin = options.begin,//开始位置 
  74.  change = options.change,//变化量 
  75.  duration = options.duration || 500,//缓动效果持续时间 
  76.  ftp = options.ftp || 50, 
  77.  onEnd = options.onEnd || function(){}, 
  78.  ease = options.ease,//要使用的缓动公式 
  79.  end = begin + change,//结束位置 
  80.  startTime = new Date().getTime();//开始执行的时间 
  81.  (function(){ 
  82.   setTimeout(function(){ 
  83.   var newTime = new Date().getTime(),//当前帧开始的时间 
  84.   timestamp = newTime - startTime,//逝去时间 
  85.   delta = ease(timestamp / duration); 
  86.   el.style.left = Math.ceil(begin + delta * change) + "px" 
  87.   if(duration <= timestamp){ 
  88.    el.style.left = end + "px"
  89.    onEnd(); 
  90.   }else
  91.    setTimeout(arguments.callee,1000/ftp); 
  92.   } 
  93.   },1000/ftp) 
  94.  })() 
  95.  } 
  96.  var Rotate = function(id){ 
  97.  try{document.execCommand("BackgroundImageCache"falsetrue);}catch(e){}; 
  98.  var container = document.getElementById(id), 
  99.  slide = container.getElementsByTagName("li")[0], 
  100.  paginater = container.getElementsByTagName("span")[0], 
  101.  links = paginater.getElementsByTagName("a"), 
  102.  images = slide.getElementsByTagName("img"), 
  103.  length = links.length, aBefore = length, aIndex = 1; 
  104.  slide.innerHTML += slide.innerHTML; 
  105.  var tip = document.createElement("li");//信息栏 
  106.  tip.style.cssText = "position:absolute;bottom:0;width:400px;height:40px;line-height:40px;text-indent:2em;"
  107.  slide.parentNode.appendChild(tip); 
  108.  if(!+"1"){ 
  109.   tip.style.cssText += "color:#369;background:#fff;filter:alpha(opacity=50)"
  110.  }else
  111.   tip.style.cssText += "color:#fff;background: rgba(164, 173, 183, .65);"
  112.  } 
  113.  var item = slide.getElementsByTagName("a"), 
  114.  critical = item[length].offsetLeft,//临界值 
  115.  distance = critical/length, 
  116.  delta = - distance; 
  117.  paginater.onclick = function(e){//实现手动切换 
  118.   e = e || window.event; 
  119.   var target = e.srcElement ? e.srcElement : e.target; 
  120.   if(target.nodeName.toLowerCase() == "a"){//事件代理 
  121.   var _aIndex = aIndex; 
  122.   aIndex = target.getAttribute("href").slice(-1); 
  123.    !+"1" ?(e.returnValue = false) :(e.preventDefault()); 
  124.   delta = - distance * _aIndex; 
  125.   var change = (aIndex - _aIndex) * distance; 
  126.   if(aIndex >= _aIndex){ 
  127.    transition(slide,{begin:delta,change: change,ease:easeInOutCubic}) 
  128.   }else
  129.    transition(slide,{begin:delta,change: -change,ease:easeInOutCubic}) 
  130.   } 
  131.   } 
  132.  }; 
  133.  (function(){/*实现自动轮换图片*/ 
  134.   setTimeout(function(){ 
  135.   (aIndex > length) && (aIndex = 1); 
  136.   delta = - distance * aIndex; 
  137.   tip.innerHTML = images[aIndex-1].getAttribute("alt");//改变信息栏的文字 
  138.   links[aBefore-1].className = "";//改变按钮的样式 
  139.   links[aIndex-1].className = "hover";//改变按钮的样式 
  140.   aBefore = aIndex; 
  141.   aIndex++; 
  142.   transition(slide,{begin:delta,change:distance,ease:easeInOutCubic}) 
  143.   setTimeout(arguments.callee,2000) 
  144.   },2000) 
  145.  })() 
  146.  } 
  147.  window.onload = function(){ 
  148.  Rotate("album"); 
  149.  } 
  150. </script> 
  151. <h4>javascript图片轮换 by 司徒正美</h4> 
  152. <div id="album"
  153.  <ul> 
  154.  <li> 
  155.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index1"
  156.   <img alt="月光下的花瓣" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg" /> 
  157.   </a> 
  158.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index2"
  159.   <img alt="清澈的湖水" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s002.jpg" /> 
  160.   </a> 
  161.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index3"
  162.   <img alt="荒漠上的植物" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s003.jpg" /> 
  163.   </a> 
  164.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index4"
  165.   <img alt="末日霓虹" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s004.jpg" /> 
  166.   </a> 
  167.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index5"
  168.   <img alt="绿·生意" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s005.jpg" /> 
  169.   </a> 
  170.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index6"
  171.   <img alt="又是收获的季节" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s006.jpg" /> 
  172.   </a> 
  173.  </li> 
  174.  </ul> 
  175.  <span> 
  176.  <a href="#index1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a> 
  177.  <a href="#index2" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a> 
  178.  <a href="#index3" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a> 
  179.  <a href="#index4" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a> 
  180.  <a href="#index5" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a> 
  181.  <a href="#index6" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6</a> 
  182.  </span> 
  183. </div> 
有的人很懒,不喜欢点击,想在按钮上一掠而过也能看到效果。这简单,我们把绑定函数独立出来,分别绑定到onclick事件与onmouseover事件上就行了。现在我们换一个缓动公式,反正这东西多着呢。比如这个pulse,像蛇信子一样来回多次振动(默认5次,有第二个参数可以自己调,我调到10次),非常有意思。你们可以试试一下子掠过所有按钮,效果是何等的炫目!
 
  1. <!doctype html> 
  2. <title>javascript图片轮换 by 司徒正美</title> 
  3. <meta charset="utf-8"/> 
  4. <meta name="keywords" content="javascript图片轮换 by 司徒正美" /> 
  5. <meta name="description" content="javascript图片轮换 by 司徒正美" /> 
  6. <style type="text/css"
  7.  #album { 
  8.  position:relative; 
  9.  width:400px; 
  10.  height:300px; 
  11.  border:10px solid #F2F1D7; 
  12.  } 
  13.  
  14.  #album ul,#album li { 
  15.  list-style:none; 
  16.  margin:0; 
  17.  padding:0; 
  18.  } 
  19.  
  20.  #album ul { 
  21.  position:relative; 
  22.  height:300px; 
  23.  width:400px; 
  24.  overflow:hidden; 
  25.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg) no-repeat 0 0; 
  26.  } 
  27.  
  28.  #album li { 
  29.  position:absolute; 
  30.  width:1000%; 
  31.  } 
  32.  
  33.  #album a { 
  34.  float:left; 
  35.  } 
  36.  
  37.  #album img { 
  38.  display:block; 
  39.  border:0; 
  40.  } 
  41.  
  42.  #album span { 
  43.  position:absolute; 
  44.  right:0; 
  45.  bottom:10px; 
  46.  } 
  47.  
  48.  #album span a { 
  49.  display:block; 
  50.  margin-right:10px; 
  51.  width:15px; 
  52.  height:15px; 
  53.  line-height:15px; 
  54.  text-align:center; 
  55.  text-decoration:none; 
  56.  color:gray; 
  57.  background:transparent url(http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_button.gif) no-repeat -15px 0; 
  58.  } 
  59.  
  60.  #album span a:hover,#album span a.hover { 
  61.  color:#F8F8F8; 
  62.  background-position:0 0; 
  63.  } 
  64. </style> 
  65. <script type="text/javascript"
  66.  var pulse = function(pos, pulses) { 
  67.  return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5; 
  68.  } 
  69.  
  70.  var transition = function(el){ 
  71.  var options = arguments[1] || {}, 
  72.  begin = options.begin,//开始位置 
  73.  change = options.change,//变化量 
  74.  duration = options.duration || 500,//缓动效果持续时间 
  75.  ftp = options.ftp || 50, 
  76.  onEnd = options.onEnd || function(){}, 
  77.  ease = options.ease,//要使用的缓动公式 
  78.  end = begin + change,//结束位置 
  79.  startTime = new Date().getTime();//开始执行的时间 
  80.  (function(){ 
  81.   setTimeout(function(){ 
  82.   var newTime = new Date().getTime(),//当前帧开始的时间 
  83.   timestamp = newTime - startTime,//逝去时间 
  84.   delta = ease(timestamp / duration,10); 
  85.   el.style.left = Math.ceil(begin + delta * change) + "px" 
  86.   if(duration <= timestamp){ 
  87.    el.style.left = end + "px"
  88.    onEnd(); 
  89.   }else
  90.    setTimeout(arguments.callee,1000/ftp); 
  91.   } 
  92.   },1000/ftp) 
  93.  })() 
  94.  } 
  95.  var Rotate = function(id){ 
  96.  try{document.execCommand("BackgroundImageCache"falsetrue);}catch(e){}; 
  97.  var container = document.getElementById(id), 
  98.  slide = container.getElementsByTagName("li")[0], 
  99.  paginater = container.getElementsByTagName("span")[0], 
  100.  links = paginater.getElementsByTagName("a"), 
  101.  images = slide.getElementsByTagName("img"), 
  102.  length = links.length, aBefore = length, aIndex = 1; 
  103.  slide.innerHTML += slide.innerHTML; 
  104.  var tip = document.createElement("li");//信息栏 
  105.  tip.style.cssText = "position:absolute;bottom:0;width:400px;height:40px;line-height:40px;text-indent:2em;"
  106.  slide.parentNode.appendChild(tip); 
  107.  if(!+"1"){ 
  108.   tip.style.cssText += "color:#369;background:#fff;filter:alpha(opacity=50)"
  109.  }else
  110.   tip.style.cssText += "color:#fff;background: rgba(164, 173, 183, .65);"
  111.  } 
  112.  var item = slide.getElementsByTagName("a"), 
  113.  critical = item[length].offsetLeft,//临界值 
  114.  distance = critical/length, 
  115.  delta = - distance; 
  116.  var manualSlippage = function(){ 
  117.   var e = arguments[0] || window.event; 
  118.   var target = e.srcElement ? e.srcElement : e.target; 
  119.   if(target.nodeName.toLowerCase() == "a"){//事件代理 
  120.   var _aIndex = aIndex; 
  121.   aIndex = target.getAttribute("href").slice(-1); 
  122.    !+"1" ?(e.returnValue = false) :(e.preventDefault()); 
  123.   delta = - distance * _aIndex; 
  124.   var change = (aIndex - _aIndex) * distance; 
  125.   (aIndex >= _aIndex) && (change = -change); 
  126.   transition(slide,{begin:delta,change: change,ease:pulse}); 
  127.   } 
  128.  } 
  129.  paginater.onmouseover = manualSlippage; 
  130.  paginater.onclick = manualSlippage; 
  131.  (function(){/*实现自动轮换图片*/ 
  132.   setTimeout(function(){ 
  133.   (aIndex > length) && (aIndex = 1); 
  134.   delta = - distance * aIndex; 
  135.   tip.innerHTML = images[aIndex-1].getAttribute("alt");//改变信息栏的文字 
  136.   links[aBefore-1].className = "";//改变按钮的样式 
  137.   links[aIndex-1].className = "hover";//改变按钮的样式 
  138.   aBefore = aIndex; 
  139.   aIndex++; 
  140.   transition(slide,{begin:delta,change:distance,ease:pulse}) 
  141.   setTimeout(arguments.callee,2000) 
  142.   },2000) 
  143.  })() 
  144.  } 
  145.  window.onload = function(){ 
  146.  Rotate("album"); 
  147.  } 
  148. </script> 
  149. <h4>javascript图片轮换 by 司徒正美</h4> 
  150. <div id="album"
  151.  <ul> 
  152.  <li> 
  153.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index1"
  154.   <img alt="月光下的花瓣" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s001.jpg" /> 
  155.   </a> 
  156.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index2"
  157.   <img alt="清澈的湖水" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s002.jpg" /> 
  158.   </a> 
  159.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index3"
  160.   <img alt="荒漠上的植物" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s003.jpg" /> 
  161.   </a> 
  162.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index4"
  163.   <img alt="末日霓虹" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s004.jpg" /> 
  164.   </a> 
  165.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index5"
  166.   <img alt="绿·生意" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s005.jpg" /> 
  167.   </a> 
  168.   <a href="http://www.cnblogs.com/rubylouvre" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="index6"
  169.   <img alt="又是收获的季节" src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s006.jpg" /> 
  170.   </a> 
  171.  </li> 
  172.  </ul> 
  173.  <span> 
  174.  <a href="#index1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a> 
  175.  <a href="#index2" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a> 
  176.  <a href="#index3" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a> 
  177.  <a href="#index4" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a> 
  178.  <a href="#index5" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a> 
  179.  <a href="#index6" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >6</a> 
  180.  </span> 
  181. </div> 
  182. <p>使用的是多次摇晃的残影特效pulse.<p> 
到此这篇关于javascript实现图片轮换动作方法的文章就介绍到这了,更多相关javascript图片轮换内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/rubylouvre/archive/2009/10/06/1578289.html