mozilla开发社区找到了:active不起作用的答案:
[1] By default, Safari Mobile does not use the :active state unless there is a touchstart event handler on the relevant element or on the <body>.
看来在iOS系统的移动设备中,需要在按钮元素或body/html上绑定一个touchstart事件才能激活:active状态。
1 2 3 |
document.body.addEventListener('touchstart', function () { //...空函数即可 }); |
将上述事件监听代码加上后,Safari Mobile上就可以看到按钮按下后的切换效果了。
参考文章: https://developer.mozilla.org/zh-CN/docs/Web/CSS/%3Aactive
转载请注明:飞飞的个人网站 » 移动端浏览器:active伪类无效的解决方法