想解释之间有什么区别的offsetHeight,clientHeight和scrollHeight或offsetWidth,clientWidth和scrollWidth?
在客户端工作之前必须知道这种差异.否则他们的一半生命将用于修复UI.
小提琴或下面的内联:
function whatis(propType) {
var mainDiv = document.getElementById("MainDIV");
if (window.sampleDiv == null) {
var div = document.createElement("div");
window.sampleDiv = div;
}
div = window.sampleDiv;
var propTypeWidth = propType.toLowerCase() + "Width";
var propTypeHeight = propType + "Height";
var computedStyle = window.getComputedStyle(mainDiv, null);
var borderLeftWidth = computedStyle.getPropertyValue("border-left-width");
var borderTopWidth = computedStyle.getPropertyValue("border-top-width");
div.style.position = "absolute";
div.style.left = mainDiv.offsetLeft + Math.round(parseFloat((propType == "client") ? borderLeftWidth : 0)) + "px"; …Run Code Online (Sandbox Code Playgroud)div.addEventListener('click', () => {
for (let i=1; i<3000; i++) {
setTimeout(() => {
let style = div.clientHeight-1;
style = style + 'px';
div.style.height = style;
},i)
}
})
Run Code Online (Sandbox Code Playgroud)
为什么这段代码不起作用?我有一个div元素500x500,我尝试动画它的高度.当我设置let style = div.clientHeight - 2;或大于2的数字时,它可以工作,但它不起作用1.问题是什么,我如何正确地使用JS动画高度?