Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

javascript - 如何防止mousemove事件在触摸设备上单击时起作用?(How can I prevent the mousemove event from working as click in touch devices?)

I have some jquery code that looks kinda like this.

(我有一些看起来像这样的jQuery代码。)

$(".bf4").each(function() {
    $(this).mousemove(function(e) {
        //some code
    });
    $(this).click(function(e) {
        //different code
    });
});

The mousemove event is for laptops and the click for cellphones.

(mousemove事件适用于笔记本电脑,而click适用于手机。)

Separately these events work fine.

(这些事件分别运行良好。)

But when I use them together (like in the code above), the code that is inside the mousemove event gets executed in cellphones and other touch devides instead of the code inside the click

(但是,当我一起使用它们时(如上面的代码), mousemove事件中的代码将在手机和其他触摸屏中执行,而不是click内部的代码。)

I removed the click part of the code and tested it again in touch devices like below.

(我删除了代码的click部分,并在如下所示的触摸设备中再次对其进行了测试。)

$(".bf4").each(function() {
    $(this).mousemove(function(e) {
        //some code
    });
});

It still works as click in touch devices.

(它仍然可以用作触摸设备中的click 。)

Long story short "The mousemove event, works like the click event in touch devices, instead of simply not working"

(长话短说: “ mousemove事件,就像触摸设备中的click事件一样,而不是根本不起作用”)

I have tested this code using touch simulation in both firefox and chrome.

(我已经在firefox和chrome中使用触摸模拟测试了此代码。)

I have also tested the code directly on my cellphone.

(我还直接在手机上测试了该代码。)

Same result everywhere.

(到处都有相同的结果。)

Now since I need to make something DIFFERENT happen in cellphones, than in laptops, I need to know why this is happening and how can I prevent it.

(现在,因为我需要做不同的东西发生在手机,比笔记本电脑,我需要知道为什么发生这种情况,我怎么能阻止它。)

Any ideas?

(有任何想法吗?)

  ask by Muhammad Usman translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...