匿名用户
您可以有效地一步一步地缩小它,直到它适合容器。
这实际上是:对元素进行样式设置,使其自然溢出
一次降低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
) {
<