我正在尝试模拟触摸事件,以防我的设备是触摸屏和悬停事件。
如果我的设备鼠标悬停在桌面设备上。但是我无法注册双击或点击事件。
这是用于在移动设备上进行测试的 codepen。我将不胜感激任何帮助或替代方式。
$('#hover-touch').on('touchstart', function(e) {
e.preventDefault();
var $elem = $(this);
if ($elem.is(':focus')) {
$elem.click();
} else {
$elem.focus();
}
});
#hover-touch {
color: red;
}
#hover-touch:hover,
#hover-touch:focus {
color: blue;
}
<a id="hover-touch" href="https://google.com">HOVER OR TOUCH</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>