iscroll.js右侧可滑动的菜单,点击每个菜单都会出现本菜单的详情

 

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>iscroll.js右侧可滑动的菜单,点击每个菜单都会出现本菜单的详情</title>
    <style type="text/css">
    body {
        margin: 0;
        overflow: hidden;
    }

    .wrapper {
        position: absolute;
        top: 0;
        bottom: 50px;
        right: 0;
        width: 200px;
        background: #f8f8f9;
    }

    .wrapper ul {
        margin: 0;
        padding: 0 10px;
    }

    .m-item {
        position: relative;
        height: 100px;
        border: 1px solid green;
        list-style: none
    }
    .m-detail{display: none; position: absolute;top: 0;left: -330px; width: 320px;height: 200px;background-color: rgba(0,0,0,0.7);}

    .footer {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 50px;
        background: #444;
    }
    </style>
</head>

<body>
    <div id="wrapper" class="wrapper" style="touch-action:none;">
        <ul id="m-list">
        </ul>
    </div>
    <div class="footer"></div>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/iScroll/5.2.0/iscroll.js"></script>
    <script type="text/javascript">
    $(function() {
        var dom = {
            list: $('#m-list')
        };
        var html = '';
        for (var i = 0 ; i < 50; i++) {
            html += '<li class="m-item js-item">' + i + ' <div class="m-detail js-detail"></div></li>'
        }
        dom.list.html(html)
        var myScroll2 = new IScroll('#wrapper', { click: true, scrollbars: true, mouseWheel: true, interactiveScrollbars:true});
        dom.list.on('mouseenter', '.js-item', function () {
            var that = $(this);
            $('.js-detail').hide();
            var detail = that.find('.js-detail');
            detail.show();
        });
        dom.list.on('mouseleave', '.js-detail', function () {
            var that = $(this);
            var detail = $('.js-detail');
            detail.hide();
        });        
    });
    </script>
</body>

</html>

 

 

posted @ 2018-08-22 14:30  徐同保  阅读(224)  评论(0编辑  收藏  举报