Implement keyboard button monitoring based on Jquery

Source: Internet
Author: User

The article from NETTUTS has a very good effect, which is a bit similar to the Flash effect. Here, I will not mention the implementation steps in the original article, the implementation logic is relatively simple, that is, the slideDown () method,

Jquery slideDown () method to achieve the sliding effect.

Copy codeThe Code is 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 ");
});
});
}

The keypress () method is used to listen to keyboard keys, which is actually not difficult, but we seldom use button listening on pages. This example is novel and worth your reference, it can be used in projects if necessary.

Copy codeThe Code is as follows:
$ (Document). keypress (function (e)
{
Switch (e. which)
{
// User presses the ""
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.