This function will work on any element without the need to add markup to your HTML.
Demo: http://jsfiddle.net/ThinkingStiff/Lpg8x/
Script:
$( 'body' ).mousemove( function( event ) { if( isNear( $( '#your-element' ), 20, event ) ) { //near } else { //not near }; } ); function isNear( $element, distance, event ) { var left = $element.offset().left - distance, top = $element.offset().top - distance, right = left + $element.width() + ( 2 * distance ), bottom = top + $element.height() + ( 2 * distance ), x = event.pageX, y = event.pageY; return ( x > left && x < right && y > top && y < bottom ); };
source share