首页 > Web开发 > 详细

面向对象原生js幻灯片代淡出效果

时间:2014-11-13 15:58:46      阅读:439      评论:0      收藏:0      [点我收藏+]

面向对象原生js幻灯片代淡出效果

下面是代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>无标题文档</title>
  6. </head>
  7. <body style="background:#CCC">
  8. <script type="text/javascript">
  9.  
  10.  
  11. var t=0;
  12. var c;
  13.  
  14. function slidingClass(id){
  15. slidingClass.id=document.getElementById(id);
  16. slidingClass.timer="3000"
  17. }
  18. slidingClass.prototype={
  19. //获取img的个数
  20. imgL:function(tag){
  21. return slidingClass.id.getElementsByTagName(tag).length;
  22. },
  23. hidden:function(){
  24. var l=slidingClass.prototype.imgL("img");
  25. for(i=0;i<l; i++){
  26. if(i!=0){
  27. slidingClass.id.getElementsByTagName("img")[i].style.display="none";
  28. }else{
  29. slidingClass.id.getElementsByTagName("img")[i].style.display="block";
  30. }
  31. }
  32. },
  33. hh:function(num){
  34. slidingClass.id.getElementsByTagName("img")[num].style.display="none"
  35. },
  36. //淡入
  37. fadeIn:function(num){
  38. var v=0;
  39. var t=setInterval(function(){
  40. var id=slidingClass.id.getElementsByTagName("img")[num];
  41. id.style.display="block";
  42. id.style.position="absolute";
  43. id.style.zIndex="9";
  44. id.filters ? id.style.filter = ‘alpha(opacity=‘ + (v+=10) + ‘)‘ : id.style.opacity = (v+=10)/100;
  45. if(v>=100){
  46. clearInterval(t);
  47. }
  48. },10)
  49. },
  50. show:function(num){
  51. var l=slidingClass.prototype.imgL("li");
  52. for(i=0;i<l; i++){
  53. slidingClass.id.getElementsByTagName("li")[i].onclick=function(){
  54. var t=this.innerHTML-1;
  55. slidingClass.prototype.show(t);
  56. slidingClass.prototype.fadeIn(t)
  57. slidingClass.prototype.hh(t==0 ? slidingClass.prototype.imgL("img")-1:t-1)
  58. slidingClass.prototype.show(t)
  59. }
  60. if(i!=num){
  61. slidingClass.id.getElementsByTagName("li")[i].className="";
  62. slidingClass.id.getElementsByTagName("img")[i].style.display="none";
  63. }else{
  64. slidingClass.id.getElementsByTagName("li")[i].className="hove";
  65. }
  66. }
  67. },
  68. //开始循环
  69. loop:function(){
  70. slidingClass.prototype.show(t);
  71. slidingClass.prototype.fadeIn(t)
  72. slidingClass.prototype.hh(t==0 ? slidingClass.prototype.imgL("img")-1:t-1)
  73. c=setTimeout("slidingClass.prototype.loop()",slidingClass.timer);
  74. //document.getElementById("n").innerHTML=noe;
  75. t++;
  76. t= t<slidingClass.prototype.imgL("img") ? t:0;
  77. slidingClass.id.onmousemove=function(){
  78. clearTimeout(c);
  79. }
  80. slidingClass.id.onmouseout=function(){
  81. c=setTimeout("slidingClass.prototype.loop()",slidingClass.timer);
  82. }
  83. },
  84. start:function(){
  85. slidingClass.prototype.hidden();
  86. slidingClass.prototype.loop();
  87. }
  88. }
  89.  
  90.  
  91.  
  92. </script>
  93. <div id="n">
  94.  
  95. </div>
  96. <div class="box" id="box">
  97.  
  98. <img src="http://image.zcool.com.cn/bigPic/1359774079165.jpg" width="1083" height="350" />
  99. <img src="http://image.zcool.com.cn/bigPic/1359774008854.jpg" width="1083" height="350" />
  100. <img src="http://image.zcool.com.cn/bigPic/1359774064447.jpg" width="1083" height="350" />
  101.  
  102. <ul id="li">
  103. <li>1</li>
  104. <li>2</li>
  105. <li>3</li>
  106. </ul>
  107. </div>
  108. <div class="shuming">
  109. 转载注明:本效果出自:<a href="http://suiyidian.cn">suiyidian.cn</a>
  110. </div>
  111. <style type="text/css">
  112. .box{
  113. width:1083px;
  114. height:350px;
  115. overflow:hidden;
  116. margin:200px auto 0px;
  117. border:3px #fff solid;
  118. position:relative;
  119. cursor:pointer;
  120. }
  121.  
  122. .box img{filter:alpha(opacity=100)}
  123. #li{padding:0px; overflow:hidden; position:absolute; right:15px; bottom:15px; z-index:999; height:22px;}
  124. #li,#li *{ margin:0px; padding:0px}
  125. #li li{ display:inline; float:left; height:20px; line-height:20px; font-size:12px; width:20px; color:#fff; background:#093; border:1px solid #fff; text-align:center; margin-left:3px}
  126. #li li.hove{ background:#0C0; font-weight:bold}
  127. .shuming {
  128. background: none repeat scroll 0 0 #333333;
  129. border: 1px solid #FFFFFF;
  130. color: #FFFFFF;
  131. font-size: 12px;
  132. height: 20px;
  133. line-height: 20px;
  134. margin: 15px auto 0;
  135. text-align: center;
  136. width: 285px;
  137. }
  138. .shuming a{color:#fff; text-decoration:none}
  139. .shuming a:hover{ text-decoration:underline; color:red}
  140. </style>
  141.  
  142. <script>
  143. var hd=new slidingClass("box");
  144. hd.start()
  145. </script>
  146. </body>
  147. </html>

面向对象原生js幻灯片代淡出效果

原文:http://www.cnblogs.com/jinhuixin/p/dianshichengjin.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!