進(jìn)階任務(wù)10

1.實現(xiàn)如下圖Tab切換的功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
      ul,li{
      margin:0;
      padding: 0;
      }
      li{
          list-style: none;
      }
      .clearfix:after{
          content: '';
          display: block;
          clear: both;
      }
      .tab-ct{
          width: 600px;
          margin: 20px auto;
          border:1px solid #ccc;
          padding:20px 10px;
          border-radius:4px;
      }
      .header li{
          float: left;
          color:cadetblue;
          width:33.3333333%;
          padding:10px 0px;
          cursor: pointer;
          background-color: red;
      }
      .content li{
          display: none;
          float: left;
          background-color: #ccc;
          width: 600px;
          height: 100px;
      }
      .header .active{
          background-color: antiquewhite;
      }
      .content .active{
          display: block;
      }
    </style>
</head>
<body>
<div class="tab-ct">
    <ul class="header clearfix">
        <li>tab1</li>
        <li>tab2</li>
        <li>tab3</li>
    </ul>
    <ul class="content clearfix" >
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul>
</div>
<script>
    var ct=document.querySelector('.tab-ct')
    var header=document.querySelector('.header')
    var headerLis=document.querySelectorAll('.header>li')
    var contentLis=document.querySelectorAll('.content>li')
    header.addEventListener('click',function () {

    })
    headerLis.forEach(function (t) {
        t.addEventListener('click',function () {
           headerLis.forEach(function (t2) {
               t2.classList.remove('active')
           })
            this.classList.add('active')
            var index=[].indexOf.call(headerLis,this)
           contentLis.forEach(function (t2) {
               t2.classList.remove('active')
           })
           contentLis[index].classList.add('active')
        })
    })
</script>
</body>
</html>

2.實現(xiàn)下圖的模態(tài)框功能,點擊模態(tài)框不隱藏,點擊關(guān)閉以及模態(tài)框以外的區(qū)域模態(tài)框隱藏

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        a{
            text-decoration: none;
            color: #333;
        }
        .modal{
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #000;
            opacity: 0.8;
            z-index: 99;
        }
        .modal-ct{
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            -webkit-transform: translate(-50%, -50%);
            width: 400px;
            border-radius: 3px;
            background: #fff;
            z-index: 100;
            border:1px solid;
        }
        .header {
            position: relative;
            height: 36px;
            line-height: 36px;
            border-bottom: 1px solid #ccc;
        }
        h3{
            margin: 0;
            padding-left: 10px;
            font-size: 16px;
        }
        .close{
            position: absolute;
            right: 10px;
            top: 10px;
            line-height: 1;
        }
        .content{
            padding: 10px;
        }
        .footer{
            padding: 10px;
            border-top: 1px solid #eee;
        }
        .btn{
            float: right;
            margin-left: 10px;
        }
        .clearfix:after{
            content: '';
            display: block;
            clear: both;
        }
        .open{
            display: block;
        }
    </style>
</head>
<body>
 <div class="btn-ct">
     <button>點我</button>
 </div>
 <div class="modal">
<div class="modal-ct">
    <div class="header">
        <h3>我是標(biāo)題</h3>
        <a class="close" href="#">x</a>
    </div>
    <div class="content">
        <p>我是內(nèi)容</p>
        <p>我是內(nèi)容</p>
    </div>
    <div class="footer clearfix">
        <a href="#" class="btn cancel">取消</a>
        <a href="#" class="btn confirm">確定</a>
    </div>
</div>
 </div>
 <script>
     var btn=document.querySelector('.btn-ct')
     var modal=document.querySelector('.modal')
     var modalCt=document.querySelector('.modal-ct')
     var close=document.querySelector('.close')
     var cancel=document.querySelector('.cancel')
     btn.addEventListener('click',function () {
        modal.classList.add('open')
     })
     close.addEventListener('click',function () {
         modal.classList.remove('open')
     })
     cancel.addEventListener('click',function () {
         modal.classList.remove('open')
     })
     modal.addEventListener('click',function () {
         modal.classList.remove('open')
     })
     modalCt.addEventListener('click',function (e) {
         e.stopPropagation()
     })
 </script>
</body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 實現(xiàn)Tab切換的功能 實現(xiàn)下圖的模態(tài)框功能,點擊模態(tài)框不隱藏,點擊關(guān)閉以及模態(tài)框以外的區(qū)域模態(tài)框隱藏
    RookieD閱讀 432評論 0 0
  • 1- 實現(xiàn)如下圖Tab切換的功能 代碼/預(yù)覽:Tab切換功能 2- 實現(xiàn)下圖的模態(tài)框功能,點擊模態(tài)框不隱藏,點擊關(guān)...
    osborne閱讀 554評論 0 1
  • 題目1: 實現(xiàn)如下圖Tab切換的功能 題目2:實現(xiàn)下圖的模態(tài)框功能,點擊模態(tài)框不隱藏,點擊關(guān)閉以及模態(tài)框以外的區(qū)域...
    mhy_web閱讀 346評論 0 0
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,355評論 25 708
  • 世界曾讓我如此孤獨,讓我在匆忙的人群中無所依靠。 我看著身邊走過的人,有的帶著微笑,有的帶著自信。而我回頭看著自己...
    歌橣閱讀 296評論 0 1

友情鏈接更多精彩內(nèi)容