I wanted to be able to put into effect the css transform property depending on the size of a container with respect to the size of the enclosing window.
With the following code, scaleCameraShutter()
is called. Zooming does occur with the re-written code for scaleCameraShutter()
and the scaling is accurate.
Here's the only remaining problem = window
resizes and so does the container
. THEN, I do a reload of the window and the correct zooming totally disappears. In short, the zooming is only temporary, not permanent??
Since this Board thrives on code, the .css specs are at the bottom ...
$(window).bind('resize', function() {
scaleCameraShutter(); // below, container is GLOBAL
});
I call:
function scaleCameraShutter() {
// .width() returns "###px"
// value before scaling
var containerWidth = parseInt( container.width() );
var windowWidth = parseInt( $(window).width() );
var theScale = windowWidth/containerWidth;
var maxContainerWidth = 480;
if (windowWidth > maxContainerWidth)
{
theScale = maxContainerWidth/containerWidth;
}
// Let the Browser pick the parm it accepts:
// IE 10 and Firefox
container.css("-transform" , "scale(" + theScale + ", " + theScale + ")");
// IE 9
container.css("-ms-transform" , "scale(" + theScale + ", " + theScale + ")");
// Firefox
container.css("-moz-transform" , "scale(" + theScale + ", " + theScale + ")");
// Chrome and Safari
container.css("-webkit-transform", "scale(" + theScale + ", " + theScale + ")");
// Opera
container.css("-o-transform" , "scale(" + theScale + ", " + theScale + ")");
}
Last, here's the css:
#container {
position: relative;
margin: 0 auto;
width: 30.00em;
height: 22.50em;
}