r/csshelp • • Sep 22 '14

Resolved Integrating CSS "Konami code" into a website

Hello, Working on a university school project about video game commentary and making a web page about it. I thought it would be fun to place the "Konami code" in the webpage so if someone were to type the sequence, something fun would pop up. Problem I'm having is I'm noticing several different versions of this.

This is what I've found.

var konami_keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];

var konami_index = 0;

$(document).keydown(function(e){

if(e.keyCode === konami_keys[konami_index++]){

    if(konami_index === konami_keys.length){
        $(document).unbind('keydown', arguments.callee);
        $.getScript('http://www.cornify.com/js/cornify.js',function(){
            cornify_add();
            $(document).keydown(cornify_add);
        }); 
    }
}else{
    konami_index = 0;
}

});

Now I'm no expert. So Question 1: one is this the "best" way to do this for a website? Question 2: If i want to add a picture and have it move around the page, what additional coding will be required?

7 Upvotes

1 comment sorted by

2

u/AutomateAllTheThings Sep 22 '14

Instead of using raw javascript, try using a library like konami-js which also has support for mobile device gestures.

As for moving things around your screen, you'll need to write your own script for that. You could use jQuery's animate methods, CSS3 animation, or another library.