javascript - CSS3 transform rotate using mouse position -
i want rotate div element using css3 "transform:rotate". want degree mouse position, tracking mouse.
how can achieve this?
thanks!
check
http://jsfiddle.net/arunberti/fsgpf/1/
$(document).ready(function() { // same yours. function rotateonmouse(e, pw) { var offset = pw.offset(); var center_x = (offset.left) + ($(pw).width() / 2); var center_y = (offset.top) + ($(pw).height() / 2); var mouse_x = e.pagex; var mouse_y = e.pagey; var radians = math.atan2(mouse_x - center_x, mouse_y - center_y); var degree = (radians * (180 / math.pi) * -1) + 100; // window.console.log("de="+degree+","+radians); $(pw).css('-moz-transform', 'rotate(' + degree + 'deg)'); $(pw).css('-webkit-transform', 'rotate(' + degree + 'deg)'); $(pw).css('-o-transform', 'rotate(' + degree + 'deg)'); $(pw).css('-ms-transform', 'rotate(' + degree + 'deg)'); } $('.drop div img').mousedown(function(e) { e.preventdefault(); // prevents dragging of image. $(document).bind('mousemove.rotateimg', function(e2) { rotateonmouse(e2, $('.drop div img')); }); }); $(document).mouseup(function(e) { $(document).unbind('mousemove.rotateimg'); }); });
Comments
Post a Comment