Jquery 悬停事件,但不在触摸/移动设备上
我正在尝试创建一个显示图像的悬停事件。在我的台式机/笔记本电脑上,它可以正常启动。但是,在手机(触摸屏)上,图像仅在点击模式链接时显示,然后图像会变粘(它会留在屏幕上) 在手机或触摸屏上,我不想触发悬停事件 这就是我的工作 HTMLJquery 悬停事件,但不在触摸/移动设备上,jquery,hover,jquery-hover,Jquery,Hover,Jquery Hover,我正在尝试创建一个显示图像的悬停事件。在我的台式机/笔记本电脑上,它可以正常启动。但是,在手机(触摸屏)上,图像仅在点击模式链接时显示,然后图像会变粘(它会留在屏幕上) 在手机或触摸屏上,我不想触发悬停事件 这就是我的工作 HTML 您可以检查它是否为触摸事件,并相应地触发悬停效果 <script> $("#test-parent").hover(function() { if(!isTouchEvent()){ $("#test-child").fadeTogg
您可以检查它是否为触摸事件,并相应地触发悬停效果
<script>
$("#test-parent").hover(function() {
if(!isTouchEvent()){
$("#test-child").fadeToggle();
}
});
function isTouchEvent() {
return 'ontouchstart' in document.documentElement
|| navigator.maxTouchPoints > 0
|| navigator.msMaxTouchPoints > 0;
}
</script>
$(“#测试父项”).hover(函数(){
如果(!isTouchEvent()){
$(“#测试子项”).fadeToggle();
}
});
函数isTouchEvent(){
在document.documentElement中返回“ontouchstart”
||navigator.maxTouchPoints>0
||navigator.msmax接触点>0;
}
来自sitepoint的@PaulOB
<script>
if (!("ontouchstart" in document.documentElement)) {
$("#test-parent").hover(function() {
$("#test-child").fadeToggle();
});
}
</script>
if(!(document.documentElement中的“ontouchstart”){
$(“#测试父项”).hover(函数(){
$(“#测试子项”).fadeToggle();
});
}
<script>
$("#test-parent").hover(function() {
if(!isTouchEvent()){
$("#test-child").fadeToggle();
}
});
function isTouchEvent() {
return 'ontouchstart' in document.documentElement
|| navigator.maxTouchPoints > 0
|| navigator.msMaxTouchPoints > 0;
}
</script>
<script>
if (!("ontouchstart" in document.documentElement)) {
$("#test-parent").hover(function() {
$("#test-child").fadeToggle();
});
}
</script>