Last active
August 29, 2015 13:56
-
-
Save jtyjty99999/8862415 to your computer and use it in GitHub Desktop.
彩蛋制造器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
感觉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