首页 > 语言 > JavaScript > 正文

JavaScript实现多个重叠层点击切换效果的方法

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

这篇文章主要介绍了JavaScript实现多个重叠层点击切换效果的方法,实例分析了javascript实现点击切换效果的相关技巧,需要的朋友可以参考下

本文实例讲述了JavaScript实现多个重叠层点击切换效果的方法。分享给大家供大家参考。具体如下:

 

 
  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"> 
  8. function $(obj){ 
  9. return document.getElementById(obj); 
  10. } 
  11. function change(n){ 
  12. for (var i=1;i<4;i++){ 
  13. if(n==i){ 
  14. $("a"+i).style.zIndex="100"; 
  15. }else{ 
  16. $("a"+i).style.zIndex="0"; 
  17. } 
  18. } 
  19. } 
  20. </script> 
  21. </head> 
  22. <body> 
  23. <div id="a1" 
  24. style="position:absolute;left:100px;top:100px;width:100px;height:100px; 
  25. background-color:#ddeeff;z-index:1" onclick="change('1')" > 
  26. </div> 
  27. <div id="a2" 
  28. style="position:absolute;left:150px;top:130px;width:100px;height:100px; 
  29. background-color:#eeffdd;z-index:2" onclick="change('2')"> 
  30. </div> 
  31. <div id="a3" 
  32. style="position:absolute;left:200px;top:160px;width:100px;height:100px; 
  33. background-color:#ffddee;z-index:3" onclick="change('3')"> 
  34. </div> 
  35. <div>http://www.vevb.com/</div> 
  36. </body> 
  37. </html> 

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

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

图片精选