I'm trying to create a document/cursor "map-overview", however i stuck at the calculation. The pointer still exceeds the overview box.
Here's what I've done so far:
var box = $('#box'),
pointer = box.find('i');
$(window).on('mousemove', function(e) {
var pageX = e.clientX,
pageY = e.clientY,
winW = $(this).width(),
winH = $(this).height(),
percentX = 100 * pageX / winW,
percentY = 100 * pageY / winH;
pointer.css({
top: percentY + '%',
left: percentX + '%'
});
});
I know, it is not the best approach to use the percentage, but i dont know how to calculate the correct dimensions... Any suggestions to make it better?