Home > Web Front-end > JS Tutorial > body text

Tab drop-down display effect of tab switching (code example)

青灯夜游
Release: 2018-10-25 15:10:20
forward
2352 people have browsed it

The content of this article is to introduce the tab drop-down display effect of tab switching (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style type="text/css">
    *{
        padding: 0;
        margin: 0;
    }
    ul,li{
        list-style: none;
    }
    #warp{
        width: 600px;
        height: auto;
        margin: 0 auto;
        margin-top: 20px;
    }
    #warp .content p{
        width: 300px;
        height: 30px;
        background-color: #000;
        color: #fff;
        line-height: 30px;
        text-align: center;
    }
    #warp .content+ .content{
        margin-top: 2px;
    }
    #warp .content ul{
        display: none;
    }
    #warp .content ul.on{
        display: block;
    }
    #warp .content li{
        background-color: #ccc;
        width: 300px;
        text-align: center;
    }
    #warp .content li + li{
        margin-top: 1px;
    }
</style>
<body>
    <p id="warp">
        <p class="content">
            <p>动物</p>
            <ul>
                <li>猴子</li>
                <li>大象</li>
                <li>狮子</li>
            </ul>
        </p>
        <p class="content">
            <p>山川</p>
            <ul>
                <li>长江</li>
                <li>黄河</li>
                <li>井水</li>
            </ul>
        </p>
        <p class="content">
            <p>美女</p>
            <ul>
                <li>貂蝉</li>
                <li>西施</li>
                <li>秀秀</li>
            </ul>
        </p>      
    </p>
    <script>
        let oP = document.getElementsByTagName("p"),
aUl = document.getElementsByTagName("ul"),
index;
            console.log(oP.length);
            for(var i=0;i<oP.length;i++){
                oP[i].index = i;
                oP[i].onclick = function(){
                index = this.index;
                aUl[index].className =  aUl[index].className === ""? "on" : "";
                console.log(i)
            }
        }
    </script>
</body>
</html>
Copy after login

Rendering:

Tab drop-down display effect of tab switching (code example)

The above is the detailed content of Tab drop-down display effect of tab switching (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!