简体   繁体   English

绝对div元素的Javascript和CSS缩放

[英]Javascript & CSS scale of absolute div elements

I have some issues with positioning of an absolute div in relation to another absolute div when using transform scale. 使用变换比例时,相对于另一个绝对div定位绝对div时,我遇到一些问题。

First I have a footer which is positioned at the bottom of the screen (window.innerHeight - footer_height) then i have another larger div above the footer that i want to position at the edge of the footer. 首先,我有一个页脚位于屏幕底部(window.innerHeight-footer_height),然后我在页脚上方有另一个较大的div,我想将其放置在页脚的边缘。 ((window.innerHeight - footer_height)-largediv_height) ((window.innerHeight-footer_height)-largediv_height)

this works fine until i try to set a transform scale of the larger div. 在我尝试设置较大div的变换比例之前,此方法效果很好。 The origin of the div is in the middle so the size increases the same on top and bottom. div的原点在中间,因此顶部和底部的大小相同。 This way the div will be partially hidden by the footer. 这样,div将被页脚部分隐藏。

How can i compensate for the increased scale in the y-axis? 如何补偿y轴上增加的比例?

I have created a fiddle as an example. 我以小提琴为例。 Resize the height of the window and look at the result. 调整窗口的高度并查看结果。 Want I want to do is to make the bottom of the scaled div to be just in line with the top of the footer. 我想要做的是使缩放后的div的底部与页脚的顶部对齐。 Any suggestions? 有什么建议么?

http://jsfiddle.net/pdjrz/30/ http://jsfiddle.net/pdjrz/30/

The Javascript Javascript

function init()
{
    scalediv = document.getElementById("scalediv");
    footer = document.getElementById("footer");
    window.addEventListener("resize", onRezise, false);
}

var onRezise = function()
{
    scale = (window.innerHeight - 33) / 251;
    w = window.innerWidth;
    h = window.innerHeight;

    footer.style.width = w+'px';
    footer.style.top = (h-33)+'px';

    scalediv.style['MozTransform'] = 'scale('+scale+','+scale+')';

    scalediv.style.top = ((h-33)-(400))+ 'px';
}

If you want the footer to be below the scalediv, put it inside the scalediv and position it bottom of scalediv. 如果希望页脚在scalediv下方,请将其放在scalediv内,并将其定位在scalediv的底部。 And make a padding-bottom on scalediv with footer's height. 然后在scalediv上以页脚的高度为底部填充。

http://jsfiddle.net/pdjrz/32/ http://jsfiddle.net/pdjrz/32/

#scalediv{padding:0 33px 0 0;}
#footer{bottom:0;}
<div id="scalediv">
    <div id="footer"></div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM