I'm answering the comment about panning at the edges here to include better formatting.
It depends on how exactly you want panning at the edges to work. Will the image move only if the mouse is moving over the edge, or even when the mouse is motionless but hovering over the edge?
In the first case: you can use the same fiddle code and just check to see if mousePosX
or mousePosY
are < 10 or > 90 (or whatever percentages you want to define as edges). If so, then instead of moving the image to a percentage of the window you'd move it to a percentage of the edge.
Since that may end up a little too sensitive, so you could go with the alternative of just moving on hover, in which case you'd use mouseEnter
and mouseLeave
events instead, and just start an interval on mouseEnter
(using var interval = setInterval(moveImage,250);
) that moves the background image a pixel, then clear that interval (clearInterval(interval);
) on mouseLeave
.
I'll leave it to you to edit the fiddle yourself and see if you can get it working how you want.