JS Implementation of DIV Highly Adaptive Window Example

  • 2021-07-21 07:11:48
  • OfStack

In this paper, an example is given to show that JS realizes DIV highly adaptive window. Share it for your reference, as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <style type="text/css">
      margin: 0;
      padding: 0;
  <script type="text/javascript">
    window.onload = windowHeight; // When the page is loaded, execute the function 
    function windowHeight() {
      var h = document.documentElement.clientHeight; // Gets the height of the visible operation area of the current window 
      var bodyHeight = document.getElementById("divContent"); // Looking for ID For content Object of 
      bodyHeight.style.height = (h - 25) + "px"; // You want to adapt to the height of the object 
    setInterval(windowHeight, 500)// Execute every half second 1 Times windowHeight Function 
  <form id="form1" runat="server">
    <div id="divContent" style="background-color: Gray;border:1px solid blue;">Test</div>

PS: Highly adaptive widely used, many online tools of this site also use this 1 skill, list the following tools for your reference:

JavaScript online formatting tool (based on beautify. js plug-in):

Online color picker tool/RGB color query comparison table:

Online personal income tax calculator:

Online inquiry of Song Ci:

For more readers interested in JavaScript related content, please check the topics on this site: "Summary of JavaScript Operation DOM Skills", "Summary of JavaScript Array Operation Skills", "Summary of JavaScript Sorting Algorithm", "Summary of JavaScript Traversal Algorithm and Skills", "Summary of JavaScript Mathematical Operation Usage", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript Search Algorithm Skills" and "Summary of JavaScript Error and Debugging Skills"

I hope this article is helpful to everyone's JavaScript programming.

Related articles: