Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 停止触摸设备:悬停?_Javascript_Jquery_Ios_Hover_Touch - Fatal编程技术网

Javascript 停止触摸设备:悬停?

Javascript 停止触摸设备:悬停?,javascript,jquery,ios,hover,touch,Javascript,Jquery,Ios,Hover,Touch,我有一个导航在悬停时打开 我希望通过触摸设备实现这一点 SASS: JQUERY: $('.menu').on('touchstart', function(e) { e.preventDefault(); if ($(this).hasClass('hover')) { $(this).removeClass('hover'); } else { $(this).addClass('hover');

我有一个导航在悬停时打开

我希望通过触摸设备实现这一点

SASS:

JQUERY:

$('.menu').on('touchstart', function(e) {
        e.preventDefault();
        if ($(this).hasClass('hover')) {
            $(this).removeClass('hover');
        } else {
            $(this).addClass('hover');
            $('.menu').not(this).removeClass('hover');
        }
    });
因此,上面的内容应该在触摸时向菜单类添加一个悬停类(如果没有),并删除所有其他悬停类。如果它确实有一个hover类,那么我希望删除它

该代码的工作原理与此不同,如果hover类已经有一个hover类,则删除它

我怀疑这是因为手机解释了:悬停

如何防止触摸设备解释:悬停


我没有使用jquery mobile。

可能重复的请阅读关于替换的回答:使用jquery mobile在触摸设备上使用其他方法悬停。我没有使用jquery mobile在发布前预读您的英语,并确保阅读该帖子。它仍然适用,因为您使用的是触摸设备。
$('.menu').on('touchstart', function(e) {
        e.preventDefault();
        if ($(this).hasClass('hover')) {
            $(this).removeClass('hover');
        } else {
            $(this).addClass('hover');
            $('.menu').not(this).removeClass('hover');
        }
    });