上上下下左右左右BA
<script>
var kkeys = "",
konami_str = "38384040373937396665",
konami_array = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
document.addEventListener('keyup', function (e) {
let key_code = e.keyCode;
if (konami_array.indexOf(key_code)===-1){
kkeys=""
return
}
kkeys+=key_code
console.log(kkeys)
if (kkeys.length===konami_str.length){
if (kkeys===konami_str){
alert("秘籍启动")
kkeys=''
}else {
console.log("错误秘籍")
kkeys=''
}
}
})
function myAlert() {
alert("function")
}
</script>
完整代码
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>Error</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
#login{
transform: translateX(-200%);
}
@keyframes show {
100%{
transform: translateX(0);
}
}
@keyframes hide {
0%{
transform: translateX(0%);
}
100%{
transform: translateX(-200%);
}
}
</style>
<script>
var kkeys = "",
konami_str = "38384040373937396665",
konami_array = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
document.addEventListener('keyup', function (e) {
let key_code = e.keyCode;
if (key_code===27){
kkeys='';
hideLogin();
return
}
if (konami_array.indexOf(key_code)===-1){
kkeys=""
return
}
kkeys+=key_code
console.log(kkeys)
if (kkeys.length===konami_str.length){
if (kkeys===konami_str){
showLogin();
kkeys=''
}else {
console.log("Error")
kkeys=''
}
}
});
function showLogin(){
let login = document.getElementById("login");
login.style.animation="show 0.7s forwards"
}
function hideLogin(){
let login = document.getElementById("login");
login.style.animation="hide 0.7s forwards"
}
</script>
</head>
<body>
<div>
<div id="login">
账号<input type="text" placeholder="输入账号"/>
密码<input type="text" placeholder="输入密码"/>
</div>
</div>
</body>
</html>