I found this: width / height after conversion
and several others, but nothing is exactly what I'm looking for. I want to scale something to 50% of its size (with a nice animated transition, of course) and change the page layout to a new (visual) element size. Apparently, by default, it happens that the element still retains its original size in the layout structure and is simply drawn using the associated transformations.
Basically, I want the user to click on a block of text (or other content), and then scale that text to 50% (or something else) of its size and paste it in the panel below to indicate that it is selected. I do not want 50% of the spaces around the element after moving it.
I tried to reset the height / width, but this causes the iself element to go through a new layout, and then the scale is applied to the new layout, and it still leaves me with a 50% space after completion, My code for the mozilla specification (for simplicity ) as follows:
<script type="text/javascript"> function zap(e) { var height = e.parentNode.offsetHeight/2 + 'px'; var width = e.parentNode.offsetWidth/2 + 'px'; e.parentNode.style.MozTransform='scale(0.0)'; e.parentNode.addEventListener( 'transitionend', function() { var selectionsArea = document.getElementById("selected"); selectionsArea.appendChild(e.parentNode); e.parentNode.style.MozTransform='scale(0.5,0.5)'; e.parentNode.style.display = 'inline-block'; e.parentNode.style.height = height; e.parentNode.style.width = width; }, true) } </script>
I really hope that I don’t have to bother with negative margins or relative positioning in order to achieve this ...
Edit: Since writing this, I have found a very similar question with no comments or answers. It is slightly different, since it doesn’t matter to me that this is an html5 solution, I suspect that the solution either does not exist or is in CSS / javascript regardless of the html level.
Scale / scale the DOM element and the space it occupies using CSS3 scale scale ()
Edit 2: (another non-working attempt)
I also tried this, but the scaling and translation functions seem to interact in such a way that the final position is impossible to predict ... and scaling before the transformation is the same as the transformation and then the scale. Unfortunately, this is not just a matter of setting translation by scale factor ...
function posX(e) { return e.offsetLeft + (e.offsetParent ? posX(e.offsetParent) : 0) } function posY(e) { return e.offsetTop + (e.offsetParent ? posY(e.offsetParent) : 0) } function placeThumbNail(e, container, x, y, scale) { var contX = posX(container); var contY = posY(container); var eX = posX(e); var eY = posY(e); var eW = e.offsetWidth; var eH = e.offsetHeight; var margin = 10; var dx = ((contX - eX) + margin + (x * eW * scale)); var dy = ((contY - eY) + margin + (y * eH * scale));
Even if this worked, the above would still require me to first move the element at the bottom of the page before running this code (to get rid of the space), and in addition, I will need to recalculate the conversion, size ... so I don't was too pleased with this attempt to start anyway.
Also note that if you use scale + trans vs trans + scale above, the result is dramatically different.
Edit 3: I figured out the placement problems ... transformations are applied in the specified order, and scale(0.5,0.5) substantially resizes the pixel by half of what it was originally from (possibly hinting at how they implemented it domestically). If I first translated, translating a little less / more, to explain the change in the position of the upper left corner caused by the scale, it will do the trick, but controlling the location of objects and adjusting the transformations when the dom changes in a reasonable manner still eludes me. This type seems wrong, because I'm drifting towards writing my layout manager in javascript to get this effect.