直接贴代码了:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="resources/scripts/jquery-1.10.1.min.js"></script>
</head>
<body>
<div class="core-title">
<h2>这里是标题</h2>
</div>
<div id="coreComparisonReportDiv" style="overflow-y:scroll; ">
<div class="tableShow">
<table style="width:5000px;">
<thead>
<tr>
<th>Remark</th>
<th>Data Set</th>
<!-- 假设这里还有很多列 -->
</tr>
</thead>
<tbody>
<tr style="">
<td style="width:120px; ">No Change</td>
<td style="width:250px; ">2019-03-15</td>
<!-- 假设这里还有很多列 -->
</tr>
<!-- 假设这里还有很多行 -->
</tbody>
</table>
</div>
</div>
</body>
</html>

下面是 Javascript 脚本:

    <script type="text/javascript">
$(document).ready(function () {
calcCoreComparisonReportDivHeight();
});
function getTableSuggestHeight(id, errorHeightValue) {
var jTable = $('#' + id);
if (jTable.length == 0) {
return;
}
var windowHeight = $(window).height();
var jTableOffsetTop = jTable.offset().top;
var iframeOffsetTop = 0;
if (window.parent != null) {
var appDivObj = window.parent.document.getElementById("app");
if (appDivObj) {
var appDivObjOffsetTop = appDivObj.offsetTop;
iframeOffsetTop = appDivObjOffsetTop;
}
}
var tempErrorHeightValue = 10;
if (errorHeightValue) {
tempErrorHeightValue = errorHeightValue;
}
var suggestHeight = windowHeight - jTableOffsetTop - iframeOffsetTop - tempErrorHeightValue; // 10 为误差
if (suggestHeight < 200) {
suggestHeight = 200; // 为了兼容 1024*768 的显示屏,最小高度 200
}
return suggestHeight;
}
function calcCoreComparisonReportDivHeight() {
var coreComparisonReportDivId = "coreComparisonReportDiv";
var coreComparisonReportDivHeight = getTableSuggestHeight(coreComparisonReportDivId);
$("#" + coreComparisonReportDivId).height(coreComparisonReportDivHeight);
}
$(window).resize(function () {
calcCoreComparisonReportDivHeight();
});
</script>

运行效果:

谢谢浏览!

利用 Javascript 让 DIV 自适应屏幕的分辨率,从而决定是否显示滚动条的更多相关文章

  1. Div 自适应屏幕大小

    http://blog.csdn.net/wodetiankong516/article/details/7827256 Background      有时, 我们需要将div或者其他的Elemen ...

  2. 怎么可以让div自适应屏幕的高度?(已解决)

    主要解决问题的方法是用JS脚本. 先看布局, 一个div是首部,另一个div是主体,主体包含左侧菜单和右侧内容. 我想把主体div的高度自适应屏幕剩余区域,怎么做? 首先,获取可见区域的高度,docu ...

  3. 限制div高度当内容多了溢出时显示滚动条

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type"content= ...

  4. Android 中Webview 自适应屏幕

    随笔 - 478  文章 - 3  评论 - 113 Android 中Webview 自适应屏幕   webview中右下角的缩放按钮能不能去掉 settings.setDisplayZoomCon ...

  5. [转载]Android中WebView自适应屏幕

    webview中右下角的缩放按钮能不能去掉 settings.setDisplayZoomControls(false); //隐藏webview缩放按钮 让Webview加载的页面居中显示有我知道的 ...

  6. 利用onresize使得div可以随着屏幕大小而自适应的代码

    原文:http://www.jb51.net/article/21831.htm 当我们让div居中时候,一般有两种方法,一种是固定左右宽度,也就是使用像素绝对定位:另一种是用百分比来相对定位,在这种 ...

  7. #region 自适应屏幕分辨率

            #region 自适应屏幕分辨率 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]        public ...

  8. Unity3D NGUI自适应屏幕分辨率(2014/4/17更新)

    原地址:http://blog.csdn.net/asd237241291/article/details/8126619 原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 本文链接地址: ...

  9. JavaScript网站设计实践(四)编写about.html页面,利用JavaScript和DOM,选择性的显示和隐藏DIV元素

    一.现在我们在网站设计(三)的基础上,来编写about.html页面. 这个页面要用到的知识点是利用JavaScript和DOM实现选择性地显示和隐藏某些DIV about.html页面在前面我们为了 ...

随机推荐

  1. 关于WIN7下IE8IE7浏览器无法安装微信支付商户证书的解决方案

    关于WIN7下IE8IE7浏览器无法安装微信支付商户证书的解决方案 解决方案就是使用 chrome浏览器 默认的chorme浏览器  打开微信商户平台 会提示让安装控件  然后反复安装 其实要解决这个 ...

  2. 使用ZeroClipboard操作剪切板

    一.ZeroClipboard下载地址 点击下载 二.添加js引用 <script src="../Assets/js/jquery-1.8.3.min.js">< ...

  3. django8-django的中间件

    1.django的客户请求流程 之前登录功能 ,需要获取用户的sesssion ,但是每个视图函数都要加装饰器来校验很不合理 ,中间件就可以解决这个问题 用户客户端--->wsgi(封装了req ...

  4. docker环境无法执行jmap -heap 56命令

    很奇怪的问题,但是jstack可以执行 解决方法: docker 内部使用jmap 需要启动容器时候配置权限:docker run --privileged=true  --cap-add=SYS_P ...

  5. 如何给HTML页面设置行高

    设置行高 由于简单还是老样子直接上代码了哦,注意:line-height属性值可以使用固定值如:20px..和百分比如:20%. 如果想让文字垂直居中如下:行高的主要作用是用来设置文本的垂直方向居中对 ...

  6. 「杂谈」最有可能成为第五个一线城市,苏州 or 杭州?

    最有可能成为第五个一线城市,苏州 or 杭州? 一线城市的几个硬指标 所谓的"一线城市",并不是政府提倡或者说是官方发布的城市称号,是最近十几年因房地产行业的强势崛起,一些媒体尤其 ...

  7. LeetCode——Department Top Three Salaries(巧妙使用子查询)

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  8. Eclipse在Tomcat环境下运行项目出现NoClassDefFoundError/ClassNotFoundException解决办法

    For this error, there can be different solutions. I have noted down the ones that had worked for me. ...

  9. Spring Cloud Gateway报错:Unable to start embedded Tomcat

    最近搭建Spring Cloud Gateway时启动项目出现如下报错信息: Error starting ApplicationContext. To display the conditions ...

  10. docker容器跨服务器的迁移的方法

    docker的备份方式有export和save两种. export是当前的状态,针对的是容器,docker save 是针对镜像images. export 找出要备份容器的ID ? 1 2 3 [r ...