首页 > 语言 > JavaScript > 正文

jQuery实现的多屏图像图层切换效果实例

2024-05-06 16:19:40
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要介绍了jQuery实现的多屏图像图层切换效果,可实现多个图层的点击切换效果,设计jQuery鼠标事件及样式的操作技巧,需要的朋友可以参考下

本文实例讲述了jQuery实现多屏图像图层切换效果的方法。分享给大家供大家参考。具体实现方法如下:

 

 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  6. <title>无标题文档</title> 
  7. <script type="text/javascript" src="jquery-1.6.2.min.js"></script> 
  8. <style type="text/css"> 
  9. ul{list-style:none;margin:0;padding:0;} 
  10. li{float:left;} 
  11. .Xing_focus{ 
  12. width:875px; height:800px; 
  13. overflow:hidden;border:1px solid red; 
  14. } 
  15. .Xing_focus ul{ 
  16. width:3500px; 
  17. } 
  18. .bnt { 
  19. float:left;width:300px;height:20px; 
  20. border:1px solid red; 
  21. } 
  22. .bnt li{ 
  23. width:18px;height:18px; 
  24. background:red; cursor:pointer; 
  25. margin-right:10px;float:left; 
  26. } 
  27. .bnt .sli{ 
  28. background:blue; 
  29. } 
  30. .next{ 
  31. width:100px;height:100px; 
  32. background:#990000;float:left; 
  33. cursor:pointer; 
  34. } 
  35. .pre{ 
  36. width:100px;height:100px; 
  37. background:#009;float:left; 
  38. cursor:pointer;margin-right:30px; 
  39. } 
  40. .list1{ 
  41. width:875px;height:500px;background:red; 
  42. } 
  43. .list2{ 
  44. width:875px;height:500px;background:black; 
  45. } 
  46. .list3{ 
  47. width:875px;height:500px;background:pink; 
  48. } 
  49. .list4{ 
  50. width:875px;height:500px;background:blue; 
  51. } 
  52. </style> 
  53. </head> 
  54. <body> 
  55. <div class="Xing_focus" id="box"> 
  56. <ul class="imgs" id="actor"> 
  57. <li class="list1"> 
  58. <img src="http://www.baidu.com/img/baidu_sylogo1.gif" /> 
  59. </li> 
  60. <li class="list2"> 
  61. <img src="http://www.baidu.com/img/baidu_sylogo1.gif" /> 
  62. </li> 
  63. <li class="list3"> 
  64. <img src="http://www.baidu.com/img/baidu_sylogo1.gif" /> 
  65. </li> 
  66. <li class="list4"> 
  67. <img src="http://www.baidu.com/img/baidu_sylogo1.gif" /> 
  68. </li> 
  69. </ul> 
  70. <ul class="bnt" id="bnt"> 
  71. </ul> 
  72. <div class="pre" id="pre">上一张</div> 
  73. <div class="next" id="next">下一张</div> 
  74. </div> 
  75. <script type="text/javascript"> 
  76. $(window).load(function() { 
  77. var liW = $("#actor li:first").width(); 
  78. var liL = $("#actor li").length; 
  79. //alert(liW) 
  80. var lis = $("#actor li").length; 
  81. for(i=0;i<lis;i++){ 
  82. $("#bnt").append("<li></li>") 
  83. $("#bnt li:first").addClass("sli"); 
  84. }; 
  85. $("#bnt li").each(function(index) { 
  86. $(this).click(function(){ 
  87. if($("#actor").is(":animated")==false){ 
  88. $("#actor").animate({"marginLeft":-index*liW},500,function(){ 
  89. $("#bnt li").removeClass("sli"); 
  90. $("#bnt li").eq(index).addClass("sli"); 
  91. }); 
  92. }; 
  93. }); 
  94. }); 
  95. settime=window.setInterval(atuoScroll,2000); 
  96. $("#box").hover(function(){ 
  97. window.clearInterval(settime); 
  98. },function(){ 
  99. settime=window.setInterval(atuoScroll,2000); 
  100. }); 
  101. //////////////////////////////////////// 
  102. $("#next").click(function(){ 
  103. var ulM =parseInt( $("#actor").css("margin-left")); 
  104. if(ulM==-((liL-1)*liW)&&$("#actor").is(":animated")==false){ 
  105. $("#actor").animate({"marginLeft":0+"px"},500,function(){ 
  106. $("#bnt li").removeClass("sli"); 
  107. $("#bnt li:first").addClass("sli"); 
  108. }); 
  109. } 
  110. else if($("#actor").is(":animated")==false){ 
  111. $("#actor").animate({"marginLeft":ulM-liW+"px"},500,function(){ 
  112. var ulM =parseInt( $("#actor").css("margin-left")); 
  113. var num = -ulM/liW 
  114. $("#bnt li").removeClass("sli"); 
  115. $("#bnt li").eq(num).addClass("sli"); 
  116. }); 
  117. };  
  118. });  
  119. //////////////////////////////////////// 
  120. $("#pre").click(function(){ 
  121. var ulM =parseInt( $("#actor").css("margin-left")); 
  122. if(ulM==0&&$("#actor").is(":animated")==false){ 
  123. $("#actor").animate({"marginLeft":-2625+"px"},500,function(){ 
  124. $("#bnt li").removeClass("sli"); 
  125. $("#bnt li:last").addClass("sli"); 
  126. }); 
  127. } 
  128. else if($("#actor").is(":animated")==false){ 
  129. $("#actor").animate({"marginLeft":ulM+liW+"px"},500,function(){ 
  130. var ulM =parseInt( $("#actor").css("margin-left")); 
  131. var num = -ulM/liW 
  132. $("#bnt li").removeClass("sli"); 
  133. $("#bnt li").eq(num).addClass("sli"); 
  134. }); 
  135. }; 
  136. }); 
  137. ////////////////////////////////////// 
  138. });//END 
  139. function atuoScroll(){ 
  140. var liW = $("#actor li:first").width(); 
  141. var liL = $("#actor li").length; 
  142. var ulM =parseInt( $("#actor").css("margin-left")); 
  143. if(ulM==-((liL-1)*liW)&&$("#actor").is(":animated")==false){ 
  144. $("#actor").stop(); 
  145. $("#actor").animate({"marginLeft":0},500,function(){ 
  146. $("#bnt li").removeClass("sli"); 
  147. $("#bnt li:first").addClass("sli");  
  148. }); 
  149. } 
  150. else if($("#actor").is(":animated")==false){ 
  151. $("#actor").stop(); 
  152. $("#actor").animate({"marginLeft":ulM-liW},500,function(){ 
  153. var ulM =parseInt( $("#actor").css("margin-left")); 
  154. var num = -ulM/liW 
  155. $("#bnt li").removeClass("sli"); 
  156. $("#bnt li").eq(num).addClass("sli");  
  157. }); 
  158. }; 
  159. }; 
  160. </script> 
  161. </body> 
  162. </html> 

希望本文所述对大家的jQuery程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选