Taken from my YouTube tutorial: https://www.youtube.com/watch?v=wWh8hwgeAMw
In this video I'll be showing you how to create a sleek PIN pad login screen using plain HTML, CSS & JavaScript - no libraries or frameworks such as jQuery or Vue.js were used in this tutorial.
This login screen is able to fire off an AJAX/Fetch request to attempt a login and then handle success by redirecting or handle incorrect pin by displaying an error state. It works in Chrome, Firefox, Microsoft Edge and Safari (hopefully - I don't have a Mac to test it :( )
BRimo BRI
class PinLogin {
constructor ({el, loginEndpoint, redirectTo, maxNumbers = Infinity}) {
this.el = {
main: el,
numPad: el.querySelector(".pin-login__numpad"),
textDisplay: el.querySelector(".pin-login__text")
};
}
new PinLogin({
el: document.getElementById("mainPinLogin"),
loginEndpoint: "login.php",
redirectTo: "dashboard.html"
});
.pin-login {
display: inline-block;
border-radius: 10px;
padding: 10px;
font-size: 28px;
background: #d9deff;
border: 1px solid #363b5e;
user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
font-family: sans-serif;
}
.pin-login__text {
margin: 10px auto 10px auto;
padding: 10px;
display: block;
width: 50%;
font-size: 0.5em;
text-align: center;
letter-spacing: 0.2em;
background: rgba(0, 0, 0, 0.15);
border: none;
border-radius: 10px;
outline: none;
cursor: default;
}
.pin-login__text--error {
color: #901818;
background: #ffb3b3;
animation-name: loginError;
animation-duration: 0.1s;
animation-iteration-count: 2;
}
@Keyframes loginError {
25% {
transform: translateX(-3px);
}
75% {
transform: translateX(3px);
}
}
@-moz-keyframes loginError {
25% {
transform: translateX(-3px);
}
75% {
transform: translateX(3px);
}
}
.pin-login__key {
width: 60px;
height: 60px;
margin: 10px;
background: rgba(0, 0, 0, 0.15);
color: #363b5e;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
font-weight: bold;
cursor: pointer;
}
.pin-login__key:active {
background: rgba(0, 0, 0, 0.25);
}