JavaScriptKonamiCode implementation code _ javascript skills

Source: Internet
Author: User
JavaScriptKonamiCode has an egg on Facebook:
Log on to facebook.com and click anywhere on your homepage. Enter Up, Up, Down, Down, Left, Right, Left, Right, B, A, and Enter on the keyboard, click the page or scroll through the scroll bar, and you will find special changes (such ).

A friend who has been playing "soul" will surely be able to see at a glance that the entered character is the "secret" in "soul ". In fact, the term "secret" is Konami Code. For details, see the figure below:

So how can I add a similar egg on my own page with JavaScript?
Abhi provides a general idea in the article Konami Code on Facebook: How to implement it on your site:

The Code is as follows:


Var $ = {
Enabled: false,
Tmp: Array (),
_ KonamiCode: Array (65,66, 39,37, 39,37, 40,40, 38,38 ),
Init: function (){
This. tmp = Array (65,66, 39,37, 39,37, 40,40, 38,38 );
},
KonamiCode: function (e ){
If (! This. enabled ){
Var t = this. tmp. pop ();
If (e. keyCode-t) = 0 ){
If (this. tmp. length = 0 ){
This. enabled = true;
}
} Else {
This. init ();
}
} Else {
This. action ();
}
},
// Change the action () function to whatever you want
Action: function (){
// Alert ("Konami Code Activated ");
}
}


However, the Abhi method is redundant. Jan Jarfalk provides a short and concise code in the message:

The Code is as follows:


Var k = [];
Function (e ){
K. push (e. keyCode );
If (k. toString (). indexOf ("38,38, 40,40, 37,39, 37,39, 66,65")> = 0 ){
// Alert ("Konami Code Activated ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.