单击键盘按键弹出窗口案例

如题(记录学习过程)

html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <link rel="stylesheet" href="tc.css">
</head>
<body>
    <div class="bodybox">
        <div class="弹窗">

            <button id="关闭">&times;</button>

            <h1>弹窗</h1>
            <p>点击链接</p>
            <a href="#">链接</a>

        </div>
    </div>

    <script>
        window.addEventListener("keydown",function(e){
            if (e.Code== "Tab") {
                document.querySelector(".弹窗").style.display = "flex"
                document.querySelector("body").style.display = "flex"
            }
        })

        document.querySelector("#关闭").addEventListener("click",function(){
            document.querySelector(".弹窗").style.display = "none"
            document.querySelector("body").style.display = "none"
        })
    </script>
</body>
</html>

tc.css文件

*{
    padding: 0px;
    margin: 0px;
}

body{
    display: none;

    background-color: rgba(90, 90, 54, 0.1);
    width: 100%;
    height: 100%;


    z-index: 8;
}

.弹窗{
    display: none;
    align-items: center;
    flex-direction: column;
    box-sizing: border-box;
    width: 20%;
    height: 100%;
    background-color: lightblue;
    position: absolute;
    padding: 40px 40px;
    left: 0%;
    top: 0%;
    border-radius: 10px;
    overflow: scroll;

    z-index: 9;
}

.弹窗 button{
    margin: -15px -10px 0 auto;
    width: 20px;
    height: 40px;
    font-size: 30px;
    background: none;
    border: none;
    cursor: pointer;
}

.弹窗 p{
    margin: 5px 20px;
    font-size: 12px;
    color: rgb(99, 98, 98);
    transition: 0.4s
}

.弹窗 a:hover {
    scale: 0.94;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值