密码显示与隐藏效果 html+css+js闭眼样式

11

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="gbk">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .kuang{
            position: relative;
            width: 380px;
            height: 60px;
            border-radius: 5px;
           /*  background-color: rgba(204, 197, 197,.5); */
            box-shadow: inset 5px 5px 10px rgba(204, 197, 197,.5),
                        inset -5px -5px 8px rgba(204, 197, 197,.5);
        }
        .kuang input{
            position: absolute;
            top: 0;
            left: 20px;
            height: 100%;
            width: 300px;
            font-size: 18px;
            outline: none;
            border: none;
            background-color:transparent;
        }
        .kuang input::placeholder{
            color: rgba(68, 67, 67,.8);
        }
        .conceal{
            position: absolute;
            top: 15px;
            right: 15px;
            width: 30px;
            height: 30px;
            background-image: url(biyan.png);
            background-size: 100% 100%;   
            cursor: pointer;
        }
        .conceal.yincang{
            background-image: url(biyan.png);
            background-size: 100% 100%; 
        }
    </style>
</head>
<body>
   <div class="kuang">
       <input type="password" placeholder=" 请输入密码......" id='password' > 
       <div class="conceal" id='conceal'></div>
   </div>
   <script>
       var password = document.getElementById('password');
       var anniu = document.getElementById('conceal');
       anniu.addEventListener('click',function(){
           if(password.type==='password')
           {
               password.setAttribute('type','text');
               anniu.classList.add('yincang');
           }else{
            password.setAttribute('type','password');
               anniu.classList.remove('yincang');
           }
       })
   </script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值