Skip to content

Instantly share code, notes, and snippets.

@jacquerie
Last active July 19, 2017 18:49
Show Gist options
  • Save jacquerie/8630208 to your computer and use it in GitHub Desktop.
Save jacquerie/8630208 to your computer and use it in GitHub Desktop.
Adds a Konami Code easter egg to a page. Requires jQuery.
var addkonamiCode = function () {
var status = 0;
$("body").keydown(function (e) {
if ((e.which === 38 && (status === 0 || status === 1))
|| (e.which === 40 && (status === 2 || status === 3))
|| (e.which === 37 && (status === 4 || status === 6))
|| (e.which === 39 && (status === 5 || status === 7))
|| (e.which === 66 && status === 8)) {
status++;
} else if (e.which === 65 && status === 9) {
$(body).append("<div class=nyanCat></div>");
$(".nyanCat").fadeOut({
complete: function () { $(this).remove(); },
duration: 2500
});
status = 0;
} else {
status = 0;
}
});
};
.nyanCat {
display: block;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 301px;
height: 119px;
background: url("img/nyan.gif");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment