源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JS实现DIV高度自适应窗口示例

  • 时间:2022-01-07 05:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JS实现DIV高度自适应窗口示例
本文实例讲述了JS实现DIV高度自适应窗口。分享给大家供大家参考,具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <style type="text/css">
    *.
    {
      margin: 0;
      padding: 0;
    }
  </style>
  <script type="text/javascript">
    window.onload = windowHeight; //页面载入完毕执行函数
    function windowHeight() {
      var h = document.documentElement.clientHeight; //获取当前窗口可视操作区域高度
      var bodyHeight = document.getElementById("divContent"); //寻找ID为content的对象
      bodyHeight.style.height = (h - 25) + "px"; //你想要自适应高度的对象
    }
    setInterval(windowHeight, 500)//每半秒执行一次windowHeight函数
  </script>
</head>
<body>
  <form id="form1" runat="server">
    <div id="divContent" style="background-color: Gray;border:1px solid blue;">Test</div>
  </form>
</body>
</html>

[b]PS:高度自适应应用广泛,本站的很多在线工具也使用了这一技巧,列举如下几个工具供大家参考:[/b] [b]JavaScript在线格式化工具(基于beautify.js插件): [/b][url=http://tools.jb51.net/code/js_beautify]http://tools.jb51.net/code/js_beautify[/url] [b]在线颜色选择器工具/RGB颜色查询对照表: [/b][url=http://tools.jb51.net/color/colorpicker]http://tools.jb51.net/color/colorpicker[/url] [b]在线个人所得税计算器: [/b][url=http://tools.jb51.net/jisuanqi/tax_calc]http://tools.jb51.net/jisuanqi/tax_calc[/url] [b]宋词在线查询: [/b][url=http://tools.jb51.net/bianmin/songci]http://tools.jb51.net/bianmin/songci[/url] 更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/332.htm]JavaScript操作DOM技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/278.htm]JavaScript数组操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/148.htm]JavaScript排序算法总结[/url]》、《[url=http://www.1sucai.cn/Special/281.htm]JavaScript遍历算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/119.htm]JavaScript数学运算用法总结[/url]》、《[url=http://www.1sucai.cn/Special/297.htm]JavaScript数据结构与算法技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/472.htm]JavaScript查找算法技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/439.htm]JavaScript错误与调试技巧总结[/url]》 希望本文所述对大家JavaScript程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部