I built the following resize script - as you can see from the fiddle, it works for scaling up but not down:
https://jsfiddle.net/calipoop/a37aeb08/
var item = document.getElementById('item'),
btn = document.getElementById('resizeBtn'),
s = 1;
btn.addEventListener('mousedown', initResize);
function initResize(e) {
var startS = s, startX = e.clientX, startY = e.clientY, dx, dy, d;
window.addEventListener('mousemove', resize);
window.addEventListener('mouseup', killResize);
function resize(e) {
dx = startX - e.clientX;
dy = startY - e.clientY;
d = Math.round(Math.sqrt(dx * dx + dy * dy));
s = startS + (d * .001);
item.style.transform = "scale(" + s + ")";
}
function killResize() {
window.removeEventListener('mousemove', resize);
window.removeEventListener('mouseup', killResize);
}
}
I tried to fix the issue by using the determinant/cross-product for a positive/negative direction:
https://jsfiddle.net/calipoop/zbx3us36/
det = (startX*e.clientY) - (e.clientX*startY);
dir = (det >= 0) ? 1 : -1; //get direction from sign of determinant
d = Math.round(Math.sqrt(dx * dx + dy * dy)) * dir;
As you can see from the fiddle, now it "sometimes" scales down, and it's always jumpy.
Any math majors with ideas? Am I getting the determinant incorrectly? Thanks in advance for any insight.