Realization of keyboard key listening _jquery based on jquery

Source: Internet
Author: User

From the nettuts see the article, the effect is very good, a bit similar to the effect of Flash, demo here, the original to realize the steps are very clear, I do not mention, the logic of achieving results is relatively simple, that is, Slidedown () method,

jquery Slidedown () method to achieve sliding effect.

Copy Code code as follows:

Shows a given element and hides all others
function Showviakeypress (element_id)
{
$ (". Container"). CSS ("display", "none");
$ (element_id). Slidedown ("slow");
}

Shows proper DIV depending on link ' href '
function Showvialink (array)
{
Array.each (function (i)
{
$ (this). Click (Function ()
{
var target = $ (this). attr ("href");
$ (". Container"). CSS ("display", "none");
$ (target). Slidedown ("slow");
});
});
}

and the keyboard key to monitor the use of the KeyPress () method, in fact, there is no difficulty, but we rarely use the button on the page to monitor, this example is more novel, it is worth our reference, if necessary, can be used in the project.

Copy Code code as follows:

$ (document). KeyPress (function (e)
{
Switch (E.which)
{
User presses the "a"
Case 97:showviakeypress ("#home");
Break

User presses the "s" key
Case 115:showviakeypress ("#about");
Break

User presses the "D" key
Case 100:showviakeypress ("#contact");
Break

User presses the "F" key
Case 102:showviakeypress ("#awards");
Break

User presses the "G" key
Case 103:showviakeypress ("#links");
}
});

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.