javascript - Function for mouse near an element in jQuery -
i want track , show tooltip when mouse near table head element. works mouseenter
event, want show tooltip before mouseenter
, when gets near. want remove tooltip after mouseout
distance table head.
this code.
$('thead').mouseenter(showtooltip); $('thead').mouseout(removetooltip);
how can jquery?
this works. first parameter can jquery object. second parameter nearness object, in case 20px
.
demo: http://jsfiddle.net/thinkingstiff/lpg8x/
script:
$( 'body' ).mousemove( function( event ) { if( isnear( $( 'thead' ), 20, event ) ) { //show tooltip here } else { //hide here }; }); 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 ); };
Comments
Post a Comment