选项卡

 选显卡的思路就是移入显示当前的内容,让其他的隐藏。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<style>
 *{
     text-align: center;
 }
 nav li{
     display: inline;
     width: 24%;
     text-decoration: none;
     padding: 15px;
 }

 section{
     height: 300px;
     position: relative;
 }

  .ss{
      width: 50px;
      height: 50px;
      background: tomato;
      position: absolute;
      top: -20px;
  }
 </style>
</head>
<body>
    <nav id="nav">
     <ul>
         <li class="act" style="background-color: gold">选卡1</li>
         <li >选卡2</li>
         <li >选卡3</li>
         <li >选卡4</li>
     </ul>
    
    </nav>
    <div id="container">
         <section class="tab" style="background-color: tomato">内容1</section>
         <section class="tab" style="background-color: cyan">内容2</section>
         <section class="tab" style="background-color: blueviolet">内容3</section>
         <section class="tab" style="background-color: gold">内容4</section>
     </div>
</body>
<script>
    var list = document.getElementsByTagName("li"); //绑定节点
    var tab = document.getElementsByClassName("tab");
    for (var k=1;k<list.length;k++){            //循环初始化样式
        tab[k].style.display="none";            //让里面的内容除了第一个其他的全部隐藏掉
        list[k].style.backgroundColor = "white" //让里面的li除了第一个其他的全部变白色
    }
    for(var i=0;i<list.length;i++){                
        list[i].index = i;                                //让i的每次的值赋给list[i] 索引
        list[i].onmouseover = function () {               //移入显示
            for (var j=0;j<list.length;j++){              //循环
                tab[j].style.display = "none"             //让内容全部隐藏
                list[j].style.backgroundColor = "white"    
            }        
            tab[this.index].style.display = "block"       //让移入的那块对应的内容显示
            this.style.backgroundColor = "gold"
        }
    }
</script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值