jquery-approach icon indicating copy to clipboard operation
jquery-approach copied to clipboard

Approach box rather than centre point

Open fgpsmith opened this issue 14 years ago • 1 comments

I was playing with approach to create a "fisheye" style text menu. However because the animation is based on distance from the centre of an object moving the mouse over the start or end of the text in the menus didn't cause much animation because with medium length text strings it was too far from the centre.

I have hacked the source to calculate distance from the object box rather than the centre (inside the box counts as a distance of zero) and thought that it was an option you might want to consider for future versions.

My distance code has not be optimised in anyway (as it should be for repeated calling) but it works for what I needed in the short term

function getDist(obj, x, y) { var offset = $(obj).offset(); minX = offset.left; maxX = minX + $(obj).width(); minY = offset.top; maxY = minY + $(obj).height(); var dX2 var dY2 if (x >= minX && x <= maxX) { dX2 = 0; } else { d1 = minX - x; d2 = maxX - x; dX2 = Math.min( d1_d1, d2_d2); } if (y >= minY && y <= maxY) { dY2 = 0; } else { d1 = minY - y; d2 = maxY - y; dY2 = Math.min( d1_d1, d2_d2); } return parseInt(Math.sqrt(dX2 + dY2)); }

fgpsmith avatar Nov 15 '11 14:11 fgpsmith

Would you be able to please post the entire .js file for this ammendment? I'm having a hard time getting this to work.

simonhrogers avatar May 24 '15 11:05 simonhrogers