I need to detect the mouse pressed event in jQuery. I see this question and it's answer. It is the exact one I needed, because here the action is happen only if the mouse is pressed and moved. It is not a click event, it is combined mouse press and move event.
I don't understand how to implement it. Currently I rotate the div using the following code, but this code is based on the mousedown event:
var rotation = 0;
jQuery.fn.rotate = function(degrees) {
$(this).css({'transform' : 'rotate('+ degrees +'deg)'});
};
$('.resizeButton').on("mousedown", function(e) {
var startX = e.pageX;
$(document).mousemove(function(e){
rotation = startX - e.pageX;
$('.test').rotate(rotation);
});
});
$('.resizeButton').on("mouseup", function(){
$(document).unbind( "mousemove" );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">Hello
<button class="resizeButton"> </button>
</div>
Please help to convert it to mouse press and move event, so that the user can easily adjust the rotation by pressing that button and rotate to any direction and release the mouse press. When the user releases the mouse press and then rotation needs to set on that particular mouse press release point.