Note that there are some explanatory texts on larger screens.

plurals
  1. POAllow user to rotate image with css & jquery
    primarykey
    data
    text
    <p>I want to allow user to rotate image like we do in photoshop, I have a created a fiddle. Something feels wrong with rotation deg, struggling since long, requesting for some help.</p> <p>Js Fiddle link - <a href="http://jsfiddle.net/madhuri2987/fZegT/8/" rel="nofollow">http://jsfiddle.net/madhuri2987/fZegT/8/</a></p> <p>Full Screen - <a href="http://jsfiddle.net/madhuri2987/fZegT/8/embedded/result/" rel="nofollow">http://jsfiddle.net/madhuri2987/fZegT/8/embedded/result/</a></p> <p>HTML</p> <pre><code>&lt;div id="mainTarget"&gt; &lt;img src="http://myreaxns.com/wp-content/uploads/2013/03/priyanka-chopra-image.jpg" width="300" class="mainTarget" /&gt; &lt;div id="target"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>JS</p> <pre><code>$(window).load(function(){ var dragging = false $(function() { var target = $('#target'); var mainTarget = $('#mainTarget'); target.mousedown(function() { dragging = true }) $(document).mouseup(function() { dragging = false }) $(document).mousemove(function(e) { if (dragging) { var mouse_x = e.pageX; var mouse_y = e.pageY; var radians = Math.atan2(mouse_x - 10, mouse_y - 10); var degree = (radians * (180 / Math.PI) * -1) + 90; mainTarget.css('-moz-transform', 'rotate(' + degree + 'deg)'); mainTarget.css('-moz-transform-origin', '50% 50%'); mainTarget.css('-webkit-transform', 'rotate(' + degree + 'deg)'); mainTarget.css('-webkit-transform-origin', '50% 50%'); mainTarget.css('-o-transform', 'rotate(' + degree + 'deg)'); mainTarget.css('-o-transform-origin', '50% 50%'); mainTarget.css('-ms-transform', 'rotate(' + degree + 'deg)'); mainTarget.css('-ms-transform-origin', '50% 50%'); } }) }) }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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