Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have an implmentation idea, as I'm going to need to write this one also, unless you already have a solution so I'd like to have it :)</p> <p>anyway, do this:</p> <p>/** edit: removed my pseudo-code in favor for the real one ahead **/ </p> <p>anyway... I'll implement this and let you know. unless of course, during the next few hours some one will send his implementation :-) /** edit: thanks for those who did **/</p> <p>UPDATE: here it is, anyway (rotating one image over another:) it's working great, jsut do a little clean up if you're importing this. it's cross browser.</p> <p>html:</p> <pre><code>&lt;div id="centered" style=" /* margin-left:400px; computed in javacript*/ "&gt; &lt;img id="static" src="" style="position:absolute; z-index:-1"&gt; &lt;img id="rotating" src="" &gt; &lt;/div&gt; </code></pre> <p>include:</p> <pre><code>// jquery.min.js, jQueryRotate.js (discussed above) </code></pre> <p>javascript:</p> <pre><code>var alpha=0 var dragOrig = null var mouseInPic = new Point(0,0) var diff var imageNo = 0 function swapImage_or_something(i /* or get src from somewhere else*/) { $("#static").attr("src", arrCfgImages[i].src) $("#rotating").attr("src", arrCfgImages[i].src) $("#static").height(450); $("#rotating").height(450); $("#centered").css ({ "margin-left": ($(document).width()-$("#static").width())/2 }) $("#rotating").rotate(0) } function doEventBinding() { $(document).bind("mousedown", function (e) { dragOrig = new Point (mouseInPic.x, mouseInPic.y) e.preventDefault() return }); $(document).bind("mouseup", function (e) { if (dragOrig) { dragOrig = null alpha+=diff diff=0 } }); $(document).bind("mousemove", function (e) { var x = -1*(Math.round($("#rotating").width()/2+0.01) - (e.pageX - $("#rotating").offset().left - (isIE ? 2 : 0))) var y = Math.round($("#rotating").height()/2+0.01) - (e.pageY - $("#rotating").offset().top - (isIE ? 2 : 0)) mouseInPic = new Point(x,y) if (dragOrig) { var cp = new Point(0,0) var deg1 = getAngleBetweenPoints(dragOrig, cp) var deg2 = getAngleBetweenPoints(mouseInPic, cp) diff = (deg1-deg2) diff = diff&lt;0 ? diff+360 : diff&gt;360 ? diff-360 : diff diff = diff&gt;180 ? diff-360 : diff //my$("debug").innerHTML = diff $('#rotating').rotate(alpha+diff); e.preventDefault() } }); } </code></pre> <p>also: </p> <pre><code>var toRAD = 1/180*Math.PI; var toDEG = 180/Math.PI; function getAngle(dx,dy) { var ang if (dx!=0) { var rad = Math.atan(dy/dx) + (dx&lt;0?Math.PI:0) ang = rad*toDEG if (ang&lt;0) ang+=360; } else { ang = dy&gt;0 ? 90 : 270; } return ang; } function getAngleBetweenPoints (p1, p2) { var dx = p1.x-p2.x var dy = p1.y-p2.y return getAngle (dx, dy) } </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.
    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