Reputation: 4537
When you mousedown
on an image, move the mouse (mousemove
) a little bit and then release (mouseup
), mouseup
is not fired with jQuery.
jsfiddle: http://jsfiddle.net/kVFTZ/
Why is this? How can I make it work when moving on an image?
Upvotes: 5
Views: 2388
Reputation: 4537
Well, I found that return false
solves the problem more appropriately.
As long as e.preventDefault()
is called, text selection will be prevented too (probably some other actions), and it can not be undone.
I added return false
to mousedown
on images only
if(e.target.tagName.toLowerCase() == 'img') {
return false;
// e.preventDefault() also does the job
// but it prevents all default action
// and can not be undone
}
updated fiddle: http://jsfiddle.net/kVFTZ/4/
Upvotes: 0
Reputation: 207861
Easy enough to fix. Add event.preventDefault();
to your mousedown function.
$(document).on('mousedown', function(event) {
event.preventDefault();
$('#info').text('Now move the mouse and then release');
$('#log').text('mouse down fired');
}).on('mouseup', function() {
$('#log').text('mouse up fired');
});
Upvotes: 4