:hover在ios无效问题

:hover 设置的样式在ios显示不出来,需要在按钮元素或body/html上绑定一个touchstart事件才能激活:active状态。

解决方案:

方案1 js绑定:

document.body.addEventListener('touchstart',function(){});

方案2 html 添加:

<body ontouchstart>

方案3:

既然iphone不支持hover,用js解决,写一个单独的类,比如.active

.active{    background-color: #eee;}123123
/*****************
在鼠标进入li的时候
1. 去除其它`li`的 `.active`
2. 给当前`li`添加类`.active`
********************/
$(function(){
    $('ul li').mouseover(function(){
        $('ul li').removeClass('active');
        $(this).addClass('active')
    })
})