I just messed around in jsfiddle trying to resize the cell base at the mouse position. Increasing the size of the box when moving the mouse is simple, just get the distance. However, I want to do the opposite; I want the drawer to grow in size as the mouse zooms in and out as the mouse moves away. I could not come up with any formulas for this. I feel that there might be something really simple that I am missing.
<div id="box"></div>
#box { height: 100px; width: 100px; background: black; }
var box = document.getElementById('box'); // center point of the box var boxX = 50; var boxY = 50; document.addEventListener('mousemove', function(e) { var x = e.pageX, y = e.pageY; var dx = x - boxX, dy = y - boxY; var distance = Math.sqrt(dx *dx + dy * dy); box.style.width = box.style.height = distance + 'px'; }, false);
Here is the link to the fiddle: http://jsfiddle.net/gSDPq/
Any help is appreciated, thanks
source share