I have a system where I'm able to drag and resize DIVs. You can grab from the top and it will grow from the bottom. Grab from the bottom and it grows down from the top. Same with left, right, and corners.
This is all done with CSS width/height and translate(x,y) and works well.
Now I'm adding rotation and using something like this:
style="transform: translate(100px,100px) rotate(-30deg);width:100px;height:50px;"
Again, this is all good.
But when I change the width or height, the element shifts up/down or left/right.
See the following. The green div is the original, and the red one has the width expanded. You can see how it shifts.
<html>
<head>
<style>
body {
position: relative;
}
.thing {
position:absolute;
border: solid 1px #0f0;
transform: translate(100px, 100px) rotate(-30deg);
}
.thing2 {
position:absolute;
border: solid 1px #f00;
transform: translate(100px, 100px) rotate(-30deg);
}
</style>
</head>
<body>
<div class="thing" style="width:100px;height:50px;"></div>
<div class="thing2" style="width:150px;height:50px;"></div>
</body>
</html>
I know I need to recalculate the top/left based on trig, but haven't found the right calculations to make it work.
Also, I'd like to keep the rotation pivot around the center, so I can't just change the pivot point to one of the corners.