Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With a newer jQuery v. you don't have to target all the <strong>-browser-specific</strong> properties.<br> Use just <code>transform</code>.</p> <p><kbd><strong><a href="http://jsbin.com/ifezoq/1/edit" rel="nofollow">LIVE DEMO</a></strong></kbd></p> <pre><code>var dragging = false; $(function() { var target = $('#target'); var mainTarget = $('#mainTarget'); var rad = mainTarget.width()/2; var elOfs = mainTarget.offset(); var elPos = { x: elOfs.left, y: elOfs.top }; target.mousedown(function() { dragging = true; }); $(document).mouseup(function() { dragging = false; }); $(document).mousemove(function(e) { if (dragging) { var mPos = { x: e.pageX-elPos.x, y: e.pageY-elPos.y }; var getAtan = Math.atan2(mPos.x-rad, mPos.y-rad); var getDeg = -getAtan/(Math.PI/180) + 135; //135 = (180deg-45deg) mainTarget.css({transform: 'rotate(' + getDeg + 'deg)'}); } }); }); </code></pre> <p>Ideally you could do something like this:</p> <p><a href="http://jsbin.com/ifezoq/2/edit" rel="nofollow">http://jsbin.com/ifezoq/2/edit</a></p> <pre><code>$(function() { var dragging = 0; var target = $('#target'); var mainTarget = $('#mainTarget'); var elOfs = mainTarget.offset(); var cent = {X: mainTarget.width()/2, Y: mainTarget.height()/2}; var elPos = {X: elOfs.left, Y: elOfs.top}; target.mousedown(function() { dragging = true; }); $(document).mouseup(function() { dragging = 0; }).mousemove(function(e) { if(dragging) { var mPos = {X: e.pageX-elPos.X, Y: e.pageY-elPos.Y}; var getAtan = Math.atan2(mPos.X-cent.X, mPos.Y-cent.Y); var getDeg = -getAtan/(Math.PI/180) + 135; mainTarget.css({transform: 'rotate(' + getDeg + 'deg)'}); } }); }); </code></pre> <p>but that would be in case you got a square image inside a circle, where the draggable corner is always at 45deg.<br> But as you can see the gap is to get the starting angle difference when handling rectangles, - you need to apply additional math, which is not needed if you ask me, so I suggest the first demo.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload