I'm attempting to develop a dynamic rotating cube that users can manipulate to their desired side by clicking and dragging on the cube. Currently, I have functionality where the cube moves as the mouse cursor moves across the screen, but this results in difficulty controlling which side of the cube you want it to face, and there's no way to stop the rotation.
You can take a look at my codepen example here: https://codepen.io/ryan_pixelers/pen/kkVErB
JQuery code responsible for rotating the cube:
$(function(){
$(window).mousemove(function(e){
$('.cube').css('transform', 'rotateX(' + - e.pageY + 'deg)' + 'rotateY(' + e.pageX + 'deg)');
});
})
I require a smooth movement similar to this, but only when the mouse is clicked. Unfortunately, mousedown doesn't seem to trigger this effect.
Thank you!