[英].mouseup() and .mousedown() not working with .mousemove()
For some reason, my .mouseup()
event is not being called. 由于某种原因,未调用我的.mouseup()
事件。 Ideally I'd like to console.log when the user activates mouseup()
. 理想情况下,当用户激活mouseup()
时,我想console.log。
Would anyone know what is wrong? 有谁知道这是怎么回事?
http://jsfiddle.net/cBh3B/ http://jsfiddle.net/cBh3B/
$('.circle').mousedown(function () {
console.log('mousedone');
$(document).mousemove(function (e) {
console.log(e.pageY);
$('.circle').offset({
left: e.pageX,
top: e.pageY
});
});
});
$('.circle').mouseup(function () {
console.log('up');
});
var p = $('.square').position();
console.log(p.left);
You are moving the circle away from the cursor once the mousedown
event is triggered. 一旦触发mousedown
事件,您就将圆圈从光标移开。 By the time the mouse button is moved up, the cursor is no longer over the circle, which means that the $('.circle').mouseup
event will not be called. 当鼠标按钮向上移动时,光标不再位于圆上,这意味着将不会调用$('.circle').mouseup
事件。
If you keep the circle under the mouse then the mouseup
event will be captured. 如果将圆圈保持在鼠标下方,则将捕获mouseup
事件。 ( See this jsFiddle demo .) ( 请参阅此jsFiddle演示 。)
EDIT: If your element is actually a 'circle' then your problem will most likely be the one evoked by @Peter Olson. 编辑:如果您的元素实际上是一个“圆圈”,那么您的问题很可能是@Peter Olson引起的。
I recommend you try using 我建议您尝试使用
$('.example').on('mouseup', function(){ console.log('mouseup'); });
Here is an example: http://jsfiddle.net/Grimbode/qsE56/ 这是一个示例: http : //jsfiddle.net/Grimbode/qsE56/
Seems this way your events are being called. 似乎是通过这种方式来调用您的事件。
$('.circle').on('mousedown',function () {
console.log('mousedone');
$(document).on('mousemove', function (e) {
console.log(e.pageY);
$('.circle').offset({
left: e.pageX,
top: e.pageY
});
});
});
$('.circle').on('mouseup', function () {
console.log('up');
});
var p = $('.square').position();
console.log(p.left);
You can also check the log, there is a clear 'up' written on it. 您也可以检查日志,上面有清晰的“向上”字样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.