JavaScript单击登录会员前端样式5.23

单击可弹出用户登录页面登录会员可关闭页面可拖动

<!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>
        .box {
            border: 1px solid gray;
            width: 500px;
            height: 200px;
            text-align: center;
            position: absolute;
            display: flex;
           
            flex-direction: column;
            justify-content: space-around;
            display: none;
            cursor: move;
        }

        .item {
            display: flex;
            justify-content: center;
        }

        .close {
            width: 15px;
            height: 15px;
            border: 1px solid gray;
            border-radius: 50%;
            position: absolute;
            right: -7px;
            top: -7px;
            text-align: center;
            line-height: 15px;
        }

        button {
            background: orange;
            color: #fff;
            border: 0;
            width: 120px;
            padding: 5px;
            border-radius: 15px;
        }

        h2 {
            text-align: center;
        }
    </style>
</head>


<body>
    <h2>单击,登录会员</h2>

    <div class="box">
        <h3>用户登录</h3>
        <div class="item">
            <div>用户名:</div>
            <input type="text">
        </div>
        <div class="item">
            <div>密&nbsp;&nbsp;&nbsp;码:</div>
            <input type="password">
        </div>
        <div class="btn">
            <button>登录</button>
        </div>
        <div class="close">X</div>
    </div>
</body>
<script>
    let header = document.querySelector("h2")
    let box = document.querySelector(".box")
    let close = document.querySelector(".close")
 
    header.addEventListener("click", function () {
        box.style.display = "flex"
    })
   
    let isDown = false
    let px=0,py=0
    box.addEventListener("mousedown", function (e) {
        isDown = true
        px=e.pageX-box.offsetLeft
        py=e.pageY-box.offsetTop
    })
    document.addEventListener("mousemove", function (e) {
        if (isDown) {
            box.style.left = e.pageX-px + "px"
            box.style.top = e.pageY-py + "px"
        }
    })
    box.addEventListener("mouseup",function(){
             isDown=false
    })
    close.addEventListener("click",function(){
             box.style.display="none";
    })
</script>

</html>
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值