1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html 自动缩放div 动态调整div的css缩放以适应容器的大小

html 自动缩放div 动态调整div的css缩放以适应容器的大小

时间:2019-12-01 17:09:57

相关推荐

html 自动缩放div 动态调整div的css缩放以适应容器的大小

匿名用户

您可以有效地一步一步地缩小它,直到它适合容器。

这实际上是:对元素进行样式设置,使其自然溢出

一次降低5%

子元素小于其父元素时停止

nullfunction calcSize() {

// The elements we need to use and our current scale

var editor = document.getElementById("editor")

var tree = document.getElementById("tree")

var scale = 1;

// Reset the initial scale and style incase we are resizing the page

tree.classList.add("loading");

tree.style.transform = "scale(1)";

// Loop until the scale is small enough to fit its container

while (

(editor.getBoundingClientRect().width <

tree.getBoundingClientRect().width) &&

(scale > 0) // This is just incase even at 0.05 scale it doesn fit, at which point this would cause an infinate loop if we didn have this check

) {

<

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。