其实原理很简单,我们点击的时候我们给元素加上一个自定义的attr,加上后便会有有一个匹配的样式去自动适配背景,几秒后去掉该样式恢复原状
首先在自己的js中拓展一个方法hoverel
. 代码如下:
$.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);
}
});
. 代码如下:
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;
}
. 代码如下:
$(e.target).hoverel();
如对本文有疑问, 点击进行留言回复!!
同事牛逼啊,写了个隐藏 bug,我排查了 3 天才解决问题!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
网友评论