【发布时间】:2022-01-23 05:44:40
【问题描述】:
我有简单的html
<head>
<style>
div.hdiv {width: 200px; height:200px; margin:5px; display:inline-block;}
div.hdiv {background: red;}
div.hdiv:hover {background: green;}
</style>
</head>
<!-- -------------------- -->
<body>
<div class="hdiv">content</div>
<div class="hdiv">content</div>
</body>
当我将手指在屏幕上拖过元素时,我希望 :hover 效果在移动设备上起作用。目前,它们仅在您点击屏幕时起作用。
如何做到这一点?
【问题讨论】:
-
你看过触摸事件吗?
-
我认为你不能只用 css,也许用 js 触摸事件? :) document.addEventListener("touchstart", function() {});
-
Laaouatni Anas,据我所知,touchstart 监听器用于模拟悬停而不点击元素。我需要 :hover (或等效的)在屏幕上移动的手指下工作。
-
@anthony3d 好的 :)
标签: javascript html jquery css hover