区分点击与鼠标按下/鼠标 [英] Differentiate click vs mousedown/mouseup

查看:132
本文介绍了区分点击与鼠标按下/鼠标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关此情况的关于stackoverflow的几个答案,但是没有一种解决方案有效.

I've read several answers on stackoverflow pertaining to this situation, but none of the solutions are working.

我正在尝试根据用户是单击元素还是使用jQuery在该元素上按住鼠标来做不同的事情.

I'm trying to do different things based upon whether a user clicks an element, or holds the mouse down on that element using jQuery.

有可能做到这一点吗?

推荐答案

这是一种方法

  1. 将变量设置为true
  2. 创建一个将在调用时将其设置为false的函数
  3. 有一个计时器(setTimeout())在mousedown()上开始递减计数
  4. 在mouseup上,清除超时,然后检查该变量是true还是false
  5. 如果为假,则单击时调用要发生的函数
  6. 无论如何,请将变量设置回true
  1. set a variable to true
  2. make a function that will set it to false when called
  3. have a timer ( setTimeout() ) start counting down on mousedown()
  4. on mouseup, clear the timeout, and check if it the variable is true or false
  5. if it is false, call the function you want to happen on click
  6. In any case, set the variable back to true

这将做您想要的. 这是一个显示其工作方式的jsfiddle: http://jsfiddle.net/zRr4s/3/

This will do what you want. Here's a jsfiddle showing how it might work: http://jsfiddle.net/zRr4s/3/

这篇关于区分点击与鼠标按下/鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆