I have a school homework where I have this issue: if you start to rotate the image, then move the mouse out of the gray area and back into the area again, but at a different location, the image "jumps": it undergoes a major rotation change. I need to avoid this inconvenience.
function init(JQuery) {
let coordX = JQuery.pageX;
let coordY = JQuery.pageY;
$(".zoneSouris").mousemove(function(event) {
if (event.buttons == 1) {
$(".zoneImage").css({
'-webkit-transform': 'rotateX(' + event.pageY + 'deg) rotateY(' + event.pageX + 'deg)',
'-moz-transform': 'rotateX(' + event.pageY + 'deg) rotateY(' + event.pageX + 'deg)',
});
} else if (event.buttons == 2) {
$(".zoneImage").css({
'-webkit-transform': 'rotate(0)',
'-moz-transform': 'rotate(0)',
});
}
});
$(".zoneSouris").bind("contextmenu", function(e) {
return false;
});
}
init($);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<main>
<div class="espaceRotation">
<div class="elemEspace zoneImage">
<img src="https://i.imgur.com/eNqPru1.png" />
</div>
<div class="elemEspace zoneSouris">
<span>Manipulez avec la souris !</span>
</div>
</div>
</main>