Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rotate image in relation to mouse position?
    primarykey
    data
    text
    <p>I'm trying to do this effect: <a href="http://metatroid.com/articles" rel="noreferrer">http://metatroid.com/articles</a> at the top of the page but I can't get it to rotate with just the code they given. </p> <pre><code> var img = $('.image'); if(img.length &gt; 0){ var offset = img.offset(); function mouse(evt){ var center_x = (offset.left) + (img.width()/2); var center_y = (offset.top) + (img.height()/2); var mouse_x = evt.pageX; var mouse_y = evt.pageY; var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y); var degree = (radians * (180 / Math.PI) * -1) + 90; img.css('-moz-transform', 'rotate('+degree+'deg)'); img.css('-webkit-transform', 'rotate('+degree+'deg)'); img.css('-o-transform', 'rotate('+degree+'deg)'); img.css('-ms-transform', 'rotate('+degree+'deg)'); } $(document).mousemove(mouse); } </code></pre> <p>So I put this code under my javascript function and changed my image class to 'image' but it still wouldn't rotate. </p> <p>Is there any other jquery or css markup associated with this or any tips you can give me to make this work? I'm still kind of new to this so any help is really appreciated. Thank you.</p> <p><strong>UPDATE</strong>: I managed to get the rotate effect to work, but it wouldn't rotate on the right axis. Here's the url for what I'm working on: <a href="http://www.lifetime-watches.com/test/i_watches.html" rel="noreferrer">http://www.lifetime-watches.com/test/i_watches.html</a> </p> <p>How do I move the axis/pivot so it'll work perfectly?</p>
    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.
 

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