'onmousedrag' event js

前端 未结 5 938
情深已故
情深已故 2020-12-18 11:24

I have some code that works each time onmouseclick and continuously onmousemove when I set them accordingly. I am looking for a way to combine the two (i.e. like a click and

5条回答
  •  旧时难觅i
    2020-12-18 11:52

    You might want to just use a flag like this: http://jsfiddle.net/n3MeH/.

    var isMouseDown = false;
    document.onmousedown = function() { isMouseDown = true  };
    document.onmouseup   = function() { isMouseDown = false };
    document.onmousemove = function() { if(isMouseDown) { /* do drag things */ } };
    

提交回复
热议问题