【发布时间】:2015-09-22 04:05:02
【问题描述】:
我希望能够根据容器的大小相对于封闭窗口的大小来实现 css 转换属性。
使用以下代码,scaleCameraShutter() 被调用。为scaleCameraShutter()重写的代码确实会发生缩放,并且缩放是准确的。
这是唯一剩下的问题 = window 调整大小,container 也是如此。然后,我重新加载窗口,正确的缩放完全消失了。总之,缩放只是暂时的,不是永久的??
由于该板在代码上蓬勃发展,因此 .css 规范位于底部...
$(window).bind('resize', function() {
scaleCameraShutter(); // below, container is GLOBAL
});
我打电话:
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 + ")");
}
最后,这是css:
#container {
position: relative;
margin: 0 auto;
width: 30.00em;
height: 22.50em;
}
【问题讨论】:
-
你能把你的代码示例发布到 plunker 之类的地方吗?
-
我真的向大家道歉......对 jsFiddle 非常陌生,只是添加了一个 jsFiddle 而不考虑它是公开的。希望这能结束它...jsfiddle.net/johnlove/yL2td3r2
标签: css-transforms