I have following code to detect the mouse move direction
var direction = ""; var oldx = 0; var oldy = 0; mousemovemethod = function(e) { if (e.pageX > oldx && e.pageY == oldy) { direction = "East"; } else if (e.pageX == oldx && e.pageY > oldy) { direction = "South"; } else if (e.pageX == oldx && e.pageY < oldy) { direction = "North"; } else if (e.pageX < oldx && e.pageY == oldy) { direction = "West"; } document.body.innerHTML = direction; oldx = e.pageX; oldy = e.pageY; } document.addEventListener('mousemove', mousemovemethod); How do I make the above code to work only
- If left or right click triggered
- When the mouse moves
- If user hold the CTRL key and moves the mouse
I know I can detect CTRL click with the following code
$(document).keyup(function(e) { if (e.keyCode == 17) { console.log("cntrl key pressed"); } }); P.s : I need a mousemove event to be called continuously as I am trying to zoom in and zoom out the charts in my application.
https://stackoverflow.com/questions/66760218/combine-multiple-event-with-mousemove March 23, 2021 at 05:13PM
没有评论:
发表评论