当前位置:网站首页>The element of display:none cannot get offsetwidth and offsetHeight

The element of display:none cannot get offsetwidth and offsetHeight

2022-06-23 20:55:00 It workers

This chapter just shares a fact , That is, if an element is set to display:none Words .

We can't get offsetWidth and offsetHeight Property value .

The code example is as follows :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Front end tribe </title>
<style type="text/css">
#antzone {
  width:200px;
  height:200px;
  display:none;
}
</style>
<script>
window.onload = function () {
  var oantzone = document.getElementById("antzone");
  var oshow = document.getElementById("show");
  var obt = document.getElementById("bt");
  obt.onclick = function () {
    oshow.innerHTML = oantzone.offsetHeight;
  }
}
</script>
</head>
<body>
<div id="antzone"></div>
<div id="show"></div>
<input type="button" id="bt" value=" See the effect "/>
</body>
</html>

As can be seen from the above code ,antzone Elemental offsetheight Can not be obtained correctly .

原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112291108582001.html