Tab切换

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        *{
            padding: 0%;
            margin: 0%;
        }

        body{
             background: #ECF0F1;
             color: #666;
             margin: 50px;
             font-family: "Helvetica Neue";
             
        }

        #tab-container{
            width: 400px;
            background: white;
            box-shadow: 1px 1px 2px rgba(0,0,0,.15);
        }

        #tab-nav{
            background: #1ABC9C;
            margin: 0%;
            padding: 0%;
        }

        #tab-nav li{
            height: 50px;
            width:100px;
            list-style: none;
            display: inline-block;
            line-height: 50px;
            text-align: center;
        }

        #tab-nav li a{
             
            text-decoration: none;
            color: white;
            /*将a标签的display设置为block,active类在加载的时候
            才可以将css样式直接添加到整个li块上,而不是只覆盖a标签*/
            display:block;
        }

        #tab-content{
            padding: 25px;
        }

        #tab-nav li a.active{
            color:#1ABC9C;
	        background:#FFF;
        }
    </style>
</head>
<body>
    <section id="tab-container">
        <ul id="tab-nav">
          <li><a href="#weather" id="nav-weather">Weather</a></li>
          <li><a href="#sport" id="nav-sport">Sport</a></li>
          <li><a href="#travel" id="nav-travel">Travel</a></li>
        </ul>
        <div id="tab-content">
          <article id="weather">
            <p>Weather is the state of the atmosphere, to the degree that it is hot or cold, wet or dry, calm or stormy, clear or cloudy. Weather, seen from an anthropological perspective, is something all humans in the world constantly experience through their senses, at least while being outside. There are socially and scientifically constructed understandings of what weather is, what makes it change, the effect it has on humans in different situations, etc. Therefore, weather is something people often communicate about.</p>
          </article>
          <article id="sport">
            <p>Sports are usually governed by a set of rules or customs, which serve to ensure fair competition, and allow consistent adjudication of the winner. Winning can be determined by physical events such as scoring goals or crossing a line first. It can also be determined by judges who are scoring elements of the sporting performance, including objective or subjective measures such as technical performance or artistic impression.</p>
          </article>
          <article id="travel">
            <p>Travel is the movement of people between relatively distant geographical locations, and can involve travel by foot, bicycle, automobile, train, boat, airplane, or other means, with or without luggage, and can be one way or round trip. Travel can also include relatively short stays between successive movements.</p>
          </article>
        </div>
        </section>

        <script type="text/javascript">
            var nav_weather = document.getElementById("nav-weather");
            var nav_sport = document.getElementById("nav-sport");
            var nav_travel = document.getElementById("nav-travel");
            var weather = document.getElementById("weather");
            var sport = document.getElementById("sport");
            var travel = document.getElementById("travel");

            //设置初始状态
            sport.style.display = 'none';
            travel.style.display = 'none';

            nav_weather.className = "active";

            

            nav_weather.onclick = function(e){
                hideAll();
                nav_weather.className = "active";
                weather.style.display = "block";
            };

            nav_sport.onclick = function(e){
                hideAll();
                nav_sport.className = "active";
                sport.style.display = "block";
            };

            nav_travel.onclick = function(e){
                hideAll();
                this.className = "active";
                travel.style.display = 'block';
            }

            function hideAll(){
                weather.style.display = "none";
                sport.style.display = "none";
                travel.style.display = "none";

                nav_weather.className = "";
                nav_sport.className = "";
                nav_travel.className = "";
                 
            }
        </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值