给我的不同部分赋予自己的高度,以便能够使它们相互重叠.我让它正常工作,但仅当页面刷新时才加载该脚本.
是否可以添加一些代码,以便在窗口大小实时更改时更新我的代码?
而且,我理解我区分三个不同小组的方法是一条捷径.有没有可能写代码,让它自己计算每个单位,这将使它更容易,如果我想要添加部分.
let div = document.querySelector(".panel-01")
var height = document.querySelector(':root');
height.style.setProperty('--height', div.clientHeight + "px");
let div2 = document.querySelector(".panel-02")
var height = document.querySelector(':root');
height.style.setProperty('--height-2', div2.clientHeight + "px");
let div3 = document.querySelector(".panel-03")
var height = document.querySelector(':root');
height.style.setProperty('--height-3', div3.clientHeight + "px");
.panel-01 {
top:calc(100vh - var(--height));
}
.panel-02 {
top:calc(100vh - var(--height-2));
}
.pangel-03 {
top:calc(100vh - var(--height-3));
}