欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jquery 點(diǎn)擊按鈕自動(dòng)高亮實(shí)現(xiàn)原理及代碼

 更新時(shí)間:2014年04月25日 15:33:54   作者:  
拓展一個(gè)點(diǎn)擊按鈕自動(dòng)高亮的原理很簡單,在點(diǎn)擊的時(shí)候給元素加上一個(gè)自定義的attr,具體實(shí)現(xiàn)祥看本文
其實(shí)原理很簡單,我們點(diǎn)擊的時(shí)候我們給元素加上一個(gè)自定義的attr,加上后便會(huì)有有一個(gè)匹配的樣式去自動(dòng)適配背景,幾秒后去掉該樣式恢復(fù)原狀

首先在自己的js中拓展一個(gè)方法hoverEl
復(fù)制代碼 代碼如下:

$.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);

}
});

其次定義樣式,當(dāng)特定attr被加上時(shí)
復(fù)制代碼 代碼如下:

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;
}

調(diào)用示例:
復(fù)制代碼 代碼如下:

$(e.target).hoverEl();

相關(guān)文章

最新評論