最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - mousehold event while doing mousemove - Stack Overflow

programmeradmin3浏览0评论

I've downloaded a JQuery plugin for a mousehold event.

/

I have this div that calls for mousemove event:

div.addEventListener('mousemove',function() {
//things
});

whenever I call the mousehold event like this:

var value = 0;
$(div).mousehold(function() {
value += 20;
$(div).html(value);
});

it would work. But if I start moving (thus, calling the mousemove event) while onmousehold, the value does not increase anymore, meaning, it stopped calling the mousehold event even if I got my left click still on hold.

How can I make it happen that when I do a mousemove, the mousehold event still works? tnx!

I've downloaded a JQuery plugin for a mousehold event.

http://remysharp./2006/12/15/jquery-mousehold-event/

I have this div that calls for mousemove event:

div.addEventListener('mousemove',function() {
//things
});

whenever I call the mousehold event like this:

var value = 0;
$(div).mousehold(function() {
value += 20;
$(div).html(value);
});

it would work. But if I start moving (thus, calling the mousemove event) while onmousehold, the value does not increase anymore, meaning, it stopped calling the mousehold event even if I got my left click still on hold.

How can I make it happen that when I do a mousemove, the mousehold event still works? tnx!

Share Improve this question asked Jan 27, 2012 at 7:01 AJ NaidasAJ Naidas 1,4347 gold badges25 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

What you're asking (at least, what I think you're asking), is simple enough with some basic logic.

By binding the mousedown, mousemove, and mouseup and setting a flag for the "down" state of the mouse, this can easily be done: JSFiddle

You could use the event object like so:

div.addEventListener('mousemove', function(event) {

  // `event.buttons` gets the state of the mouse buttons
  // 0 = not pressed, 1 = left click pressed, 2 = right click pressed
  if (event.buttons === 1) {
    value += 20;
  }

});
发布评论

评论列表(0)

  1. 暂无评论