I’m making a jquery parallax effect where when the user first hovers the mouse over the document, the foreground layer will move towards the mouse cursor such that the mouse cursor will be over the center of the foreground layer. Afterwards, when the user moves around the mouse cursor, the foreground layer should move the opposite direction of the mouse cursor; the background layer will also move in the opposite direction but slower to produce the parallax effect.
The problem is that after the foreground layer moves toward the mouse cursor using the mouseover event and I trigger the mousemove event, the foreground and background layers will “jump” to another location.
I have updated your example and it seems, that it works ok now (at least in Google Chrome 15 and IE9).
http://jsfiddle.net/jPFAq/10/
Basically, I have changed
mouseovertomouseenterand made the coordinates calculation inmouseentersame as inmousemove.UPDATE:
In addition I have removed the use of a variable and I’m just unsubscribing from the
mousemoveevent (jQuery.unbind), while themouseenterhandler is running.Here is the code for reference: