现在有一个列表页。是有li 组成的。如下
<li>你好</li> <li>你好</li> <li>你好</li> <li>你好</li>
在手机上点击的时候希望有些反馈。所以就加了下面的css
li:active{ background-color:#ddd; }
但是在移动端滑动的时候,手指触摸到这些li节点上的时候也会变色。请问怎么处理可以只是点击的时候触发背景色改变。而在滑动的时候不触发背景色改变呢?
学习是最好的投资!
The best way is to use js. Use a delay function to automatically remove class
class
.active{ background-color:#ddd; }
$('li').on('click', function (e) { var _this = this; $(_this).addClass('active'); setTimeout(function () { $(_this).removeClass('active'); }, 150); });
The mobile sliding event is touchmove, maybe you can make a fuss about it. One solution is to remove :active and change to js event control
el.addEventListener('touchstart',function(){ //加背景色 }) el.addEventListener('touchend',function(){ //移除背景色 }) el.addEventListener('touchmove',function(){ //如果有背景色,就移除 })
This seems to be the case?
body:active li:active, li { background-color: initial; } li:active{ background-color: #ddd; }
The code has not been tested for mobile phone answering, but if you use css, it feels like it is written like this; or you can use js directly.
The best way is to use js. Use a delay function to automatically remove
that adds background colorclass
The mobile sliding event is touchmove, maybe you can make a fuss about it. One solution is to remove :active and change to js event control
This seems to be the case?
The code has not been tested for mobile phone answering, but if you use css, it feels like it is written like this; or you can use js directly.