tab选项卡切换

				版权声明:可任意转载,转载注明出处。					https://blog.csdn.net/Handsome_fan/article/details/70456153				</div>
							            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-5edb848729.css">
					<div class="htmledit_views" id="content_views">

本人在上一篇文章也写了用JS来实现tab选项卡切换效果,但是上次的那个代码比较复杂,这次是简化版的。


  
  
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Tab效果 </title>
  6. <style type="text/css">
  7. ul{
  8. list-style: none;
  9. }
  10. *{
  11. margin: 0;
  12. padding: 0;
  13. }
  14. #tab{
  15. border: 1px solid #ccc;
  16. margin: 20px auto;
  17. width: 403px;
  18. border-top: none;
  19. }
  20. .list ul{
  21. overflow: hidden;
  22. }
  23. .list li{
  24. float: left;
  25. }
  26. .list li{
  27. padding-left: 28px;
  28. padding-right: 28px;
  29. padding-top: 6px;
  30. padding-bottom: 6px;
  31. border: 1px solid #ccc;
  32. background: -moz-linear-gradient(top, #FEFEFE, #EDEDED);
  33. background: -webkit-gradient(linear,left top,left bottom, from(#fefefe), to(#ededed));
  34. border-right: none;
  35. cursor: pointer;
  36. }
  37. #listCon{
  38. height: 100px;
  39. }
  40. #listCon div{
  41. padding: 10px;
  42. position:absolute;
  43. opacity: 0;
  44. filter: alpha(opacity=0);
  45. }
  46. .list li :first-child{
  47. border-left: none;
  48. }
  49. .list li :hover{
  50. background: #fff;
  51. border-bottom: none;
  52. }
  53. .list li .cur{
  54. background: #fff;
  55. border-bottom: none;
  56. }
  57. #listCon div .cur{
  58. opacity: 1;
  59. filter: alpha(opacity=100);
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div id="tab">
  65. <div class="list">
  66. <ul>
  67. <li class="cur">许嵩 </li>
  68. <li>周杰伦 </li>
  69. <li>林俊杰 </li>
  70. <li>陈奕迅 </li>
  71. </ul>
  72. </div>
  73. <div id="listCon">
  74. <div class="cur">断桥残雪、千百度、幻听、想象之中 </div>
  75. <div>红尘客栈、牛仔很忙、给我一首歌的时间、听妈妈的话 </div>
  76. <div>被风吹过的夏天、江南、一千年以后 </div>
  77. <div>十年、K歌之王、浮夸 </div>
  78. </div>
  79. </div>
  80. <script type="text/javascript">
  81. window.onload = function(){
  82. var oDiv = document.getElementById( "tab");
  83. var lis = oDiv.getElementsByTagName( "li");
  84. var oDivCon = document.getElementById( "listCon");
  85. var lisDiv = oDivCon.getElementsByTagName( "div");
  86. for( var i= 0;i<lis.length;i++){
  87. lis[i].index = i;
  88. lis[i].onmouseover = function(){
  89. show( this.index);
  90. }
  91. }
  92. function show(a){
  93. for( var j= 0;j<lis.length;j++){
  94. lis[j].className = "";
  95. lisDiv[j].className = "";
  96. }
  97. lis[a].className = "cur";
  98. lisDiv[a].className = "cur";
  99. }
  100. }
  101. </script>
  102. </body>
  103. </html>





				版权声明:可任意转载,转载注明出处。					https://blog.csdn.net/Handsome_fan/article/details/70456153				</div>
							            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-5edb848729.css">
					<div class="htmledit_views" id="content_views">

猜你喜欢

转载自blog.csdn.net/weixin_44392418/article/details/86103000