手风琴实现效果js(flex版本)

<!DOCTYPE html>
<html>
<head>
    <title>js实现手风琴效果</title>
    <meta charset="utf-8">
    <style>
        body{
            margin: 0;
            padding: 0;
        }

        #box{
            width: 96%;
            height: 200px;
            padding: 2% 2%;
            overflow:hidden;
        }
        #box ul{
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            list-style-type: none;
            display: flex;
            flex-direction: row;
            overflow:hidden;
        }
        #box ul li{
           flex: 1;
              background: url(http://img.elongstatic.com/index/ifold/20150422_ifold1.jpg) no-repeat center;
        }
    </style>
    <script>
        window.onload = function() {
            var aLi = document.querySelectorAll('li');

            aLi.forEach(function(val, index) {

               // 如果鼠标划入的话  那么就让这个元素的flex 值为2
                val.onmouseover = function(e) {
                    e.target.style.flex = 2;
                }

              // 如果划出的话  那么就返回原来的位置

                val.onmouseout = function(e) {
                    e.target.style.flex = 1;
                }
            })

        }
    </script>
</head>
<body>
    <div id="box">
       <ul>
           <li></li>
           <li></li>
           <li></li>
           <li></li>
           <li></li>
           <li></li>
       </ul>
    </div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_39081958/article/details/82118920