:hover在ios无效问题
:hover 设置的样式在ios显示不出来,需要在按钮元素或body/html上绑定一个touchstart事件才能激活:active状态。
解决方案:
方案1 js绑定:
1 |
document.body.addEventListener('touchstart',function(){}); |
方案2 html 添加:
1 |
<body ontouchstart> |
方案3:
既然iphone不支持hover,用js解决,写一个单独的类,比如.active
1 |
.active{ background-color: #eee;}123123 |
1 2 3 4 5 6 7 8 9 10 11 |
/***************** 在鼠标进入li的时候 1. 去除其它`li`的 `.active` 2. 给当前`li`添加类`.active` ********************/ $(function(){ $('ul li').mouseover(function(){ $('ul li').removeClass('active'); $(this).addClass('active') }) }) |
最新评论