Know JS in the mouse press release mousedown,mouseup and key events Keydown,keyup__js

Source: Internet
Author: User

Recently do the front desk, to do a button on the special effects, requirements are pressed down to see is pressed down the feeling. Well, just follow the effect, and the background picture of the two buttons that have already been used in the PS process. Then it should be using CSS and JS to control the effect of it.


Before learning JS has always had a keydown,keyup impression, literally does not seem to be the key press down and open the English, so use this function to try. Later I have not come out of the desired effect, I was puzzled, and then Baidu know that the mouse button and keyboard keys are not the same.

Keydown,keyup: A keyboard key that belongs to you

Mousedown,mouseup: The mouse button that belongs to you

We can't confuse it.


Here's My Code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

The corresponding Keydown,keyup event annotation, you use the mouse to press that button, will appear effect. Letting go will restore the original effect.

If you try to comment out the Mousedown,mouseup event, you first select the button, and then casually on your keyboard to press which button will also appear effect, release and restore.

We can debug, as the above code I quoted the jquery JS file, the button background picture is their own preparation, everyone debugging words to prepare the above two can be.


For a further explanation of the KeyDown event, the W3cschool is very detailed, and the following example is the example on W3cschool, which can be used to listen to an example of a specific key on your keyboard that you press: (mostly. which this attribute)

 


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.