Skip to content

Instantly share code, notes, and snippets.

@jtyjty99999
Last active August 29, 2015 13:56
Show Gist options
  • Save jtyjty99999/8862415 to your computer and use it in GitHub Desktop.
Save jtyjty99999/8862415 to your computer and use it in GitHub Desktop.
彩蛋制造器
感觉cheet.js挺有意思的,制造页面彩蛋,随便写了一个
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
function egg(arr, callback) {
this.sequence = arr.join(',');
this.length = arr.length;
this.pressed = [];
this.callback = callback
this.init();
}
egg.prototype = {
constructor : egg,
init : function () {
document.addEventListener('keyup', this.handleKey.bind(this), false)
},
handleKey : function (e) {
this.pressed.push(e.keyCode)
console.log(this.pressed)
this.check()
},
check : function () {
if (this.pressed.join(',') == this.sequence) {
this.callback();
this.pressed = [];
} else if (this.pressed.length == this.length) {
this.pressed.shift()
}
}
}
var d = new egg([38, 40, 38, 40], function () {
alert('go!')
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment