By default, Safari Mobile does not use the :active state unless there is a touchstart event handler on the relevant element or on the .—MDN
document.body.addEventListener('touchstart', function (){});
<body touchstart> <!-- ... --> </body>
<!-- 省略 -->
<li data-touch="true">
点我
</li>
<!-- 省略 -->
<script>
document.body.addEventListener('touchstart', function(e){
var target = e.target
if(target.dataset.touch === 'true'){
target.classList.add('active')
}
})
document.body.addEventListener('touchmove', function(e){
var target = e.target,
rect = target.getBoundingClientRect()
if(target.dataset.touch === 'true'){
// 移出元素时,取消active状态
if(e.changedTouches[0].pageX<rect.left || e.changedTouches[0].pageX>rect.right || e.changedTouches[0].pageY<rect.top || e.changedTouches[0].pageY>rect.bottom){
target.classList.remove('active')
}
}
})
document.body.addEventListener('touchcancel', function(e){
var target = e.target
if(target.dataset.touch === 'true'){
target.classList.remove('active')
}
})
document.body.addEventListener('touchend', function(e){
var target = e.target
if(target.dataset.touch === 'true'){
target.classList.remove('active')
}
})
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有