页面功能引导

效果图

 

实现原理 

通过元素的 定位层级 z-index   以及 指引的显示隐藏  

实现代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        .main {
            width: 100%;
            height: 100%;
            background-color: #f0f0f0;
            overflow: hidden;
        }

        ul {
            display: flex;
            flex-wrap: wrap;
        }

        li {
            list-style: none;
            width: 300px;
            height: 400px;
            text-align: center;
            background-color: #fff;
            font-size: 20px;
            position: relative;
            margin: 20px;
        }

        li>div:nth-child(1) {
            width: 300px;
            height: 400px;
            line-height: 400px;
            position: absolute;
        }

        li>div:nth-child(2) {
            width: 230px;
            height: 25px;
            line-height: 25px;
            position: absolute;
            right: 0;
            bottom: -33px;
            background-color: #fff;
            border-radius: 5px;
            cursor: pointer;
            left: 135px;
            display: none;
        }

        .center {
            position: fixed;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1;
            display: none;
        }
    </style>
</head>

<body>
    <div class="main">
        <ul>
            <li>
                <div>这是列表一</div>
                <div>
                    <span>测试第一个数据</span>
                    <span>第一步</span>
                </div>
            </li>
            <li>
                <div>这是列表四</div>
                <div>
                    <span>测试第四个数据</span>
                    <span>第四步</span>
                </div>
            </li>
            <li>
                <div>这是列表二</div>
                <div>
                    <span>测试第二个数据</span>
                    <span>第二步</span>
                </div>
            </li>
            <li>
                <div>这是列表三</div>
                <div>
                    <span>测试第三个数据</span>
                    <span>第三步</span>
                </div>
            </li>
        </ul>
        <div class="center">
        </div>
    </div>

    <script>
        let Mask = document.querySelector(".center")
        let domlist = document.querySelectorAll("li")
        console.log(Mask)
        // 默认第一项展示
        showDom(0)

        // 设置元素的显示
        function showDom(index) {
            Mask.style.display = "block"
            domlist[index].children[1].style.display = "block"
            domlist[index].style.zIndex = 5
        }

        // 设置元素的隐藏
        function hideDom() {
            Mask.style.display = "none"
            for (let i = 0; i < domlist.length; i++) {
                domlist[i].children[1].style.display = "none"
                domlist[i].style.zIndex = 1
            }
        }

        domClick()

        // 点击事件
        function domClick() {
            domlist[0].children[1].onclick = function () {
                console.log("141")
                hideDom()
                showDom(2)
            }

            domlist[1].children[1].onclick = function () {
                hideDom()
            }

            domlist[2].children[1].onclick = function () {
                hideDom()
                showDom(3)
            }

            domlist[3].children[1].onclick = function () {
                hideDom()
                showDom(1)
            }
        }
    </script>
</body>

</html>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值