原生js简单音乐播放列表

原生js简单音乐播放列表_第1张图片

<!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>
        * {
            margin: 0;
            padding: 0;
        }

        .wrapper {
            width: 200px;
            height: auto;
            border: 1px solid #424242;
            margin: 0 auto;
            margin-top: 200px;
        }

        .wrapper ul {
            width: 200px;
            height: auto;

        }

        .wrapper ul li {
            list-style-type: none;

        }

        .header {
            width: 198px;
            height: auto;
            border: 1px solid #424242;
            background-color: #424242;
            color: #fff;
            text-align: center;
        }

        .buttom {
            width: 0px;
            height: 0px;
            border: 8px solid red;
            ;
            border-left-color: transparent;
            border-bottom-color: transparent;
            border-right-color: transparent;
            position: absolute;
            left: 844px;
            top: 208px;
            cursor: pointer;
        }

        a {
            display: block;
            /* 超链接变块状元素 */
            text-decoration: none;
            font-size: 15px;
            line-height: 20px;
            color: #424242;
        }

        .box ul{
            display: none;
        }
        a:hover {
            background-color: #424242;
            opacity: 0.3;
            color: #fff;
        }
        
    </style>
</head>

<body>
    <div class="wrapper" id="wrapper">
        <div class="header" id="header">播放列表
            <div class="buttom" id="buttom"></div>
        </div>
        <div class="box" id="box">
            <ul>
                <li><a href="#">爱的故事上集-孙耀威</a></li>
                <li><a href="#">春秋-张敬轩</a></li>
                <li><a href="#">孤单背影-陈慧娴</a></li>
                <li><a href="#">堆积情感-邝美云</a></li>
                <li><a href="#">风继续吹Live-张国荣</a></li>
            </ul>
        </div>
    </div>


    <script>
        var oBtn = document.getElementById("buttom");
        var oBox = document.getElementById("box");
        var oUl = document.getElementById("box").getElementsByTagName("ul")[0];

        oBtn.onclick = function(){
            oUl.style.display =  oUl.style.display == "block" ? "none" : "block";
                         
        }
        //三目运算符判断,与下if条件判断语句同,二选一使用


        oBtn.onclick = function(){
            if(oUl.style.display == "block"){//判断一定要用==
                oUl.style.display = "none";
            }else{
                oUl.style.display = "block";
            }
        }
        //正常的if条件判断

    </script>
</body>

</html>

你可能感兴趣的:(原生js,Demo)