Tuesday 15 June 2010

jquery - Dynamically rotate image according to distance from mouse -


I have an image, and want to rotate it, however, I do not think the CSS keyframe will work because they are dynamic form Can not change from I am currently using a jquery plugin on jquery rotate what I want to do, changes the rotation speed from element to mouse. Is there any solution that is not very intensive (hopefully) CPU, because the JQR rotate is already very useless of CPU power. Here's my code:

  var angle = 0; Var distance = 200; Set interval (function () {plus = distance / 100; angle = = plus; $ ("# AMM"). Rotate (angle);}, 25);   

See the JSfield that rotates the image to 2 degrees each loop. What I would like to do, increases the speed of rotation as the mouse passes (by changing the "distance" variable).

Edit: Bella has been updated here:


MouseX & amp; Y in the body with the body. PageX & amp; Y is your image offset address using element.offset ()

  $ (document) .ready (function () {$ ('body'). Mousemove (function (e) {/ / Was to put an image in the coating box because it was rotating var offset = $ ('# container') offset (); var distance x = e. Pagex - (offset.left + ($ ('# amm'). () / 2)); var range Y = E. Gageo - (offset.top + ($ ('# ames'). Altitude () / 2));}    

No comments:

Post a Comment