相关疑难解决方法(0)

什么是offsetHeight,clientHeight,scrollHeight?

想解释之间有什么区别的offsetHeight,clientHeightscrollHeightoffsetWidth,clientWidthscrollWidth

在客户端工作之前必须知道这种差异.否则他们的一半生命将用于修复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)

html javascript dom offsetheight

205
推荐指数
4
解决办法
10万
查看次数

当我尝试使用setTimeout()为它设置动画时,div不会变小?

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动画高度?

html javascript css

1
推荐指数
1
解决办法
53
查看次数

标签 统计

html ×2

javascript ×2

css ×1

dom ×1

offsetheight ×1