JS-实现横向手风琴

横向手风琴--

鼠标悬浮某一张图片,图片显示,其他图片影藏。

<div class="content">
        <ul>
            <li class="current"><img src="./img4/1.jpg" alt="" height="400"></li>
            <li><img src="./img4/2.jpg" alt="" height="400"></li>
            <li><img src="./img4/3.jpg" alt="" height="400"></li>
            <li><img src="./img4/4.jpg" alt="" height="400"></li>
            <li><img src="./img4/5.jpg" alt="" height="400"></li>
        </ul>   
    </div>
<style>
        *{
            margin: 0;
            padding: 0;
        }
        .content {
            width: 1000px;
            height: 400px;
            margin: 100px auto;
            overflow: hidden;
            box-shadow: 0 0 2px 2px gray;
        }
        ul{
            width: 100%;
            height: 100%;
            list-style: none;
            display: flex;
        }
        li{
            width: 70px;
            height: 100%;
            overflow: hidden;
            transition: 0.5s;
        }
        .current{
            flex-grow: 10;
        }
    </style>
<script>
        let content = document.getElementsByClassName("content")[0];
        let lis = document.getElementsByTagName("li");


        let fn1 = function () {
            for(let i=0;i<lis.length;i++){
                lis[i].className = "";
            }
            this.className = "current";
        }

        for (let i = 0; i < lis.length; i++) {
            lis[i].addEventListener("mouseenter", fn1, "false");
        }
    </script>

 

posted @ 2019-09-25 09:33  blog_CccK  阅读(726)  评论(0编辑  收藏  举报