Konami code using jQuery
![]()
The Konami code is a pretty cool way to hide easter eggs on your website. If you want to include the code on your site but something like Konami-JS is a little too heavy you could try this small jQuery snippet.
function konami(fn) {
var input = "";
var pattern = "3838404037393739666513";
$(document).keydown(function(e) {
input += e.keyCode;
if (input.indexOf(pattern) !== -1) {
fn();
input = "";
}
});
}
The function gets one argument: a function that is executed when the code is passed correctly. Use it like this:
$(document).ready(function() {
konami(function() {
alert("You did the Konami! W00t!");
});
});
Tweets die vermelden Always fun: include the Konami code in your website using this small jQuery snippet: -- Topsy.com
[…] Dit blogartikel was vermeld op Twitter door OOBE, Hay Kranen. Hay Kranen heeft gezegd: Always fun: include the Konami code in your website using this small jQuery snippet: http://bit.ly/catcXG […]
frenkie
Yep, great code! Every day is Easter ;) Only wish somebody would invent a way for the iPhone to input it.
Hay
Well, you can use KonamiJS (link in the post) for that, it has a iPhone input option.
Yasmine
Hello! Thank you for sharing! I wanted to know what the purpose of the fn() is doing in your if statement?