当前位置:   article > 正文

用JS写的一个简单的导航栏_用js写一个导航条

用js写一个导航条
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>选项卡</title>
  6. <style>
  7. * {
  8. margin: 0;
  9. padding: 0;
  10. }
  11. span {
  12. display: inline-block;
  13. margin-left: 30px;
  14. width: 150px;
  15. height: 40px;
  16. background: #FFFFFF;
  17. border-bottom: 2px solid #8A2BE2;
  18. font: 16px/40px "微软雅黑";
  19. text-align: center;
  20. color: #000000;
  21. }
  22. span.current,
  23. span:hover {
  24. background: #8A2BE2;
  25. color: #FFFFFF;
  26. }
  27. .hd {
  28. height: 40px;
  29. }
  30. .bd {
  31. height: 400px;
  32. padding: 10px 30px;
  33. font-size: 50px;
  34. }
  35. .bd>div {
  36. display: none;
  37. }
  38. .bd .show {
  39. display: block;
  40. }
  41. </style>
  42. <script>
  43. window.onload = function() {
  44. var sp = document.getElementsByTagName("span");
  45. var cons = document.querySelector(".bd").getElementsByTagName("div");
  46. for(var i = 0; i < sp.length; i++) {
  47. sp[i].index = i;
  48. sp[i].onmouseover = function() {
  49. for(var j = 0; j < sp.length; j++) {
  50. sp[j].className = "";
  51. cons[j].className = "";
  52. }
  53. this.className = "current";
  54. cons[this.index].className = "show";
  55. }
  56. }
  57. }
  58. </script>
  59. </head>
  60. <body>
  61. <div class="tab_box">
  62. <div class="hd">
  63. <span class="current">新闻</span>
  64. <span>军事</span>
  65. <span>房产</span>
  66. <span>体育</span>
  67. <span>娱乐</span>
  68. </div>
  69. <div class="bd">
  70. <div class="show">我是骑车新闻</div>
  71. <div>我是军事新闻</div>
  72. <div>我是房产新闻</div>
  73. <div>我是体育新闻</div>
  74. <div>我是娱乐新闻</div>
  75. </div>
  76. </div>
  77. </body>
  78. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/69369
推荐阅读
相关标签
  

闽ICP备14008679号