Jquery Click button automatically highlight implementation principle and code

Source: Internet
Author: User

In fact, the principle is very simple, we click on the element plus a custom attr, plus there will be a matching style to automatically match the background, after a few seconds to remove the style back to the original

First of all, in their own JS to expand a method Hoverel

The 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);

}

});

Next defines the style, when a specific attr is added

The 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:

The code is as follows:

$ (e.target). Hoverel ();

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.