jquery Programming Glossary: math.atan2
jQuery rounded slider http://stackoverflow.com/questions/10186135/jquery-rounded-slider var mPos x e.clientX elPos.x y e.clientY elPos.y var atan Math.atan2 mPos.x radius mPos.y radius deg atan Math.PI 180 180 final.. and calculate the Y and X atan2 X Y yes inverted atan Math.atan2 mouseCoordX radius mouseCoordY radius Now we have to transform..
jQuery animation for a hover with 'mouse direction' http://stackoverflow.com/questions/3627042/jquery-animation-for-a-hover-with-mouse-direction TRBL top right bottom left var direction Math.round Math.atan2 y x 180 Math.PI 180 90 3 4 do your animations here switch direction.. to get the direction should be var direction Math.round Math.atan2 y x 1.57079633 5 4 where 1.57... is Math.PI 2 This is much more..
Rotate sprite javascript http://stackoverflow.com/questions/3851896/rotate-sprite-javascript .offset .top Get radians using atan2 var radians Math.atan2 e.pageY cannonY e.pageX cannonX Convert to degrees var degrees.. function e degree is arctan y over x soh cah toa degree Math.atan2 e.pageY imgY e.pageX imgX 180 Math.PI degree degree 90 360 jQuery..
How to rotate image in relation to mouse position? http://stackoverflow.com/questions/7195825/how-to-rotate-image-in-relation-to-mouse-position 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..
Get element -moz-transform:rotate value in jQuery http://stackoverflow.com/questions/8270612/get-element-moz-transformrotate-value-in-jquery ' ' var a values 0 var b values 1 var angle Math.round Math.atan2 b a 180 Math.PI else var angle 0 return angle 0 angle 360 angle..
Rotating an element based on cursor position in a separate element http://stackoverflow.com/questions/9972449/rotating-an-element-based-on-cursor-position-in-a-separate-element 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..
jQuery rounded slider http://stackoverflow.com/questions/10186135/jquery-rounded-slider function e mdown false .mousemove function e if mdown var mPos x e.clientX elPos.x y e.clientY elPos.y var atan Math.atan2 mPos.x radius mPos.y radius deg atan Math.PI 180 180 final 0 360 positive degrees from mouse position X Math.round radius.. add the radius to our calculation. radius half width height and calculate the Y and X atan2 X Y yes inverted atan Math.atan2 mouseCoordX radius mouseCoordY radius Now we have to transform the atan ized small floated number to degrees angle keeping..
jQuery animation for a hover with 'mouse direction' http://stackoverflow.com/questions/3627042/jquery-animation-for-a-hover-with-mouse-direction and do a modulo by 4 to shift the quadrants to a proper clockwise TRBL top right bottom left var direction Math.round Math.atan2 y x 180 Math.PI 180 90 3 4 do your animations here switch direction case 0 animations from the TOP break case 1 animations.. 3 animations from the LEFT break of course the short notation to get the direction should be var direction Math.round Math.atan2 y x 1.57079633 5 4 where 1.57... is Math.PI 2 This is much more efiicient bit harder for me to explain since it skips the..
Rotate sprite javascript http://stackoverflow.com/questions/3851896/rotate-sprite-javascript the dom var cannonX obj.cannon .offset .left var cannonY obj.cannon .offset .top Get radians using atan2 var radians Math.atan2 e.pageY cannonY e.pageX cannonX Convert to degrees var degrees radians 180 Math.PI And this is where I am I mean since the.. degree imgX position.left imgY position.top #main .mousemove function e degree is arctan y over x soh cah toa degree Math.atan2 e.pageY imgY e.pageX imgX 180 Math.PI degree degree 90 360 jQuery normalizes pageX and pageY transfrom from 180 to 180 0..
How to rotate image in relation to mouse position? http://stackoverflow.com/questions/7195825/how-to-rotate-image-in-relation-to-mouse-position 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..
Get element -moz-transform:rotate value in jQuery http://stackoverflow.com/questions/8270612/get-element-moz-transformrotate-value-in-jquery matrix 'none' var values matrix.split ' ' 1 .split ' ' 0 .split ' ' var a values 0 var b values 1 var angle Math.round Math.atan2 b a 180 Math.PI else var angle 0 return angle 0 angle 360 angle angle1 getRotationDegrees '#myDiv' angle2 getRotationDegrees..
Rotating an element based on cursor position in a separate element http://stackoverflow.com/questions/9972449/rotating-an-element-based-on-cursor-position-in-a-separate-element 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..
|