39.密码长度改变图片模糊

密码长度改变图片模糊

html部分

Image Password Strength

Change the password to see the effect

Submit

css部分

*{
    margin: 0;
    padding: 0;
}
body{
    height: 100vh;
    overflow: hidden;
    
}
.bg{
    content: "";
    position: absolute;
    background-image: url('./static/20180529205331_yhGyf.jpeg');
    inset: 0;
    filter: blur(10px);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;   
}

.container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    z-index: 2;
    padding: 40px;
    background-color: #fff;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 10px 10px -5px rgba(0, 0, 0, 0.6);
}
h1{
    font-size: 26px;
    white-space: nowrap;
}
h3{
    font-size: 16px;
    font-weight: 400;
    white-space: nowrap;
    text-align: center;
    margin: 10px 0;
}
label{
    display: block;
    margin: 5px 0;
    font-size: 16px;
    text-align: left;
}
.email{
    margin: 10px 0;
    text-align: left;
}
.password{
    margin: 10px 0;
    text-align: left;
}

input{
    width: 250px;
    height: 10px;
    padding: 10px;
    padding-right: 60px;
    border: 1px solid #ccc;
}
.button{
    padding: 10px 30px;
    background-color: black;
    color: white;
    width: 200px;
    text-align: center;
    margin: 10px auto;
    margin-top: 30px;
    border-radius: 10px;
}
.button:active{
    transform: scale(0.96);
    cursor: pointer;
}

js部分

// 获取dom
const password = document.querySelector('#password');
const bg = document.querySelector('.bg');

// 监听密码框的改变
password.addEventListener("input", function (e) {
    const res=scale(this.value.length,0,20,10,0);
    bg.style.filter = `blur(${res}px)`;
})

// 在一个范围中取另一个范围
const scale = (num, in_min, in_max, out_min, out_max) => {
    return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

效果

39.密码长度改变图片模糊_第1张图片

你可能感兴趣的:(前端开发小案例,css,javascript,前端)