Jquery click the button to automatically highlight implementation principle and code

Source: Internet
Author: User

In fact, the principle is very simple. When we click it, we add a custom attr to the element, and a matching style will automatically adapt to the background. After a few seconds, the style will be removed and restored to its original state.

First, expand the hoverEl method in your own js.
Copy codeThe Code is as follows:
$. Extend ($. fn ,{
HoverEl: function (){

Var _ this = $ (this );
Var _ t = setTimeout (function (){
_ This. attr ("hover", "on ");
}, 10 );
_ This. attr ("hoverTimeout", _ t );

SetTimeout (function (){
ClearTimeout (_ this. attr ("hoverTimeout "));
Var _ t = setTimeout (function (){
_ This. removeAttr ("hover ");
},100 );
_ This. attr ("hoverTimeout", _ t );
},200 );

}
});

Second, define the style. When a specific attr is added
Copy codeThe Code is as follows:
Li [hover = on] {
Background-image:-webkit-gradient (linear, 0% 100%, 0% 0%, from (# 194FDB), to (#4286F5 ))! Important;
Background-image:-webkit-linear-gradient (top, #4286F5, # 194FDB )! Important;
Color: white! Important;
Cursor: pointer! Important;
}

Call example:
Copy codeThe Code is as follows:
Objects (e.tar get). hoverEl ();

Related Article

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.