我该如何创建一个函数来检测可滚动的正文何时溢出?

凯尔

我*创建了一个可滚动的表,该表仅向上滚动,tbody而其余部分保持固定,这就是应该的样子,但是,当表tbody不够大时,我做的小技巧是使滚动条不tbody排列因为它不排列。我如何创建一个函数来检测它(各行td何时超出了表的大小(假设它的高度为100%),所以我可以更改表的设置

前任:

function detector(){
  if(table.overflow-y:is_on){
    //bla
  }
} 

*我们实际上是StackOverflow社区,我,谢谢!健康长寿·繁荣昌盛。

当行数多于表格的行数时,height就可以了: 在此处输入图片说明

但是如果没有... 在此处输入图片说明

th, td {
  word -
    break: break -all;
}
html {
  width: 100 % ;
  height: 100 % ;
  overflow: hidden;
}

body {
  background: #FFF;
  color: #000;font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;margin: 10px;	padding: 0;}

table, td, a {color: # 000;
  font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans - serif
}
h1 {
  font: normal normal 18px Verdana,
  Geneva,
  Arial,
  Helvetica,
  sans - serif;
  margin: 0 0 5px 0
}
div.tableContainer {
  clear: both;
  border: 1px solid #963;padding-right:1px;height: 285px;overflow: auto;width: 100%;}

html>body div.tableContainer {overflow: hidden;width: 100%;height:83%;}
div.tableContainer table {float: left;width: 100%;height:100%;}


html>body div.tableContainer table {
	width: calc(100% - 16px);
    height:100%;
}


thead.fixedHeader tr {
	position: relative
}

html>body thead.fixedHeader tr {
	display: block
}

thead.fixedHeader th {
	background: # C96;
  border - left: 1px solid# EB8;
  border - right: 1px solid# B74;
  border - top: 1px solid# EB8;
  font - weight: normal;
  padding: 4px 3px;
  text - align: left;
}

thead.fixedHeader a, thead.fixedHeader a: link, thead.fixedHeader a: visited {
  color: #FFF;
  display: block;
  text - decoration: none;
  width: 100 % ;

}

thead.fixedHeader a: hover {
  color: #FFF;
  display: block;
  text - decoration: underline;
  width: 100 % ;
}

html > body tbody.scrollContent {
  display: block;
  overflow: auto;
  width: 100 % ;
  height: 100 % ;
}

/* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/                             */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
  background: #FFF;
  border - bottom: none;
  border - left: none;
  border - right: 1px solid# CCC;
  border - top: 1px solid# DDD;
  padding: 2px 3px 3px 4px
}

tbody.scrollContent tr.alternateRow td {
  background: #EEE;
  border - bottom: none;
  border - left: none;
  border - right: 1px solid# CCC;
  border - top: 1px solid# DDD;
  padding: 2px 3px 3px 4px
}

.scrollTable, .scrollContent {
  overflow: visible;
}

html > body tbody.scrollContent {
  width: calc(100 % +17px);
}
th,
td {
  word-break: break-all;
}
html {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  background: #FFF;
  color: #000;
  font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
  margin: 10px;
  padding: 0;
}
table,
td,
a {
  color: #000;
  font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
}
h1 {
  font: normal normal 18px Verdana, Geneva, Arial, Helvetica, sans-serif;
  margin: 0 0 5px 0
}
div.tableContainer {
  clear: both;
  border: 1px solid #963;
  padding-right: 1px;
  height: 285px;
  overflow: auto;
  width: 100%;
}
html>body div.tableContainer {
  overflow: hidden;
  width: 100%;
  height: 83%;
}
div.tableContainer table {
  float: left;
  width: 100%;
  height: 100%;
}
html>body div.tableContainer table {
  width: calc(100% - 16px);
  height: 300px;
}
thead.fixedHeader tr {
  position: relative
}
html>body thead.fixedHeader tr {
  display: block
}
thead.fixedHeader th {
  background: #C96;
  border-left: 1px solid #EB8;
  border-right: 1px solid #B74;
  border-top: 1px solid #EB8;
  font-weight: normal;
  padding: 4px 3px;
  text-align: left;
}
thead.fixedHeader a,
thead.fixedHeader a:link,
thead.fixedHeader a:visited {
  color: #FFF;
  display: block;
  text-decoration: none;
  width: 100%;
}
thead.fixedHeader a:hover {
  color: #FFF;
  display: block;
  text-decoration: underline;
  width: 100%;
}
html>body tbody.scrollContent {
  display: block;
  overflow: auto;
  width: 100%;
  height: 100%;
}
/* make TD elements pretty. Provide alternating classes for striping the table */

/* http://www.alistapart.com/articles/zebratables/                             */

tbody.scrollContent td,
tbody.scrollContent tr.normalRow td {
  background: #FFF;
  border-bottom: none;
  border-left: none;
  border-right: 1px solid #CCC;
  border-top: 1px solid #DDD;
  padding: 2px 3px 3px 4px
}
tbody.scrollContent tr.alternateRow td {
  background: #EEE;
  border-bottom: none;
  border-left: none;
  border-right: 1px solid #CCC;
  border-top: 1px solid #DDD;
  padding: 2px 3px 3px 4px
}
.scrollTable,
.scrollContent {
  overflow: visible;
}
html>body tbody.scrollContent {
  width: calc(100% + 17px);
}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title>Pure CSS Scrollable Table with Fixed Header</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta http-equiv="language" content="en-us">

  <style type="text/css"></style>
</head>

<body>

  <h1>Pure CSS Scrollable Table with Fixed Header</h1>


  <div id="tableContainer" class="tableContainer">
    <table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable" id="Stable">
      <thead class="fixedHeader">
        <tr class="alternateRow">
          <th><a href="#">Header 1ahjsgdhjagsdhjgahjsdghjasgdhjagshjdgahjsdghjagsdhj</a>
          </th>
          <th><a href="#">Header 2</a>
          </th>
          <th><a href="#">Header 3</a>
          </th>
          <th><a href="#">Header 2</a>
          </th>
          <th><a href="#">Header 3</a>
          </th>
          <th><a href="#">Header 2</a>
          </th>
          <th><a href="#">Header 3</a>
          </th>
        </tr>
      </thead>
      <tbody class="scrollContent">
        <tr class="normalRow">
          <td>123</td>
          <td>123</td>
          <td>123</td>
          <td>123</td>
          <td>123</td>
          <td>123</td>
          <td>123</td>
        </tr>
        <tr class="alternateRow">
          <td>More Cell Content 1</td>
          <td>More Cell Content 2</td>
          <td>More Cell Content 3</td>
          <td>Cell Content 2</td>
          <td>Cell Content 3</td>
          <td>Cell Content 2</td>
          <td>Cell Content 3</td>
        </tr>

      </tbody>
    </table>
  </div>

  <div>
    <br>
  </div>



</body><span class="gr__tooltip"><span class="gr__tooltip-content"></span><i class="gr__tooltip-logo"></i><span class="gr__triangle"></span></span>

</html>

德文·H
var tbody = $('.scrollContent'),
    theader = $('.fixedHeader'),
    table = $('#Stable');

console.log(tbody[0].scrollHeight);
console.log(theader.height());
console.log(table.height());

if(table.height() - theader.height() < tbody[0].scrollHeight){
  console.log('Overflowed height of table');
} else {
  console.log('Did not overflow.');
}

我相信这就是您要寻找的。它使用jQuery,但可以根据需要将其转换为原始Javascript。

tbody[0].scrollHeight给出了TBODY的实际高度。因此,如果此值大于表格的高度-页眉的高度,则会创建一个滚动条。

http://plnkr.co/edit/pSvM6S0HbEfIwMyo2NbQ?p=preview

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何创建一个函数来查找给定两个参数的可整除位数

我该如何写一个函数来填充文件中的向量

为什么我们要创建一个单独的函数来检测其他类的输入

我如何创建一个函数来测试输入是否包含任何字符?

我如何创建一个函数来更改数组中的值?

我们如何创建一个递归函数来查找数字的最高位数?

我如何创建一个函数来读取用户在C中插入数组的数字?

我如何创建一个函数来检查对象JavaScript数组中的布尔字段

可滚动的DIV,我想创建一个动画,该动画在页面加载时滚动到div的底部

如何创建一个函数来计算年份?

如何定义一个函数来创建列表

如何创建一个函数来选择特定的数组?

我为可滚动页面和不可滚动页面创建了一个模板。有没有一种方法可以组合这些并使用参数来设置可滚动或不可滚动?

如何创建一个函数来保存一个代码块然后执行?

PyQt:如何创建一个可滚动的窗口

当我创建一个函数来处理xhrhttp请求时,如何解决未捕获的类型错误?

我正在创建一个函数来搜索文件中的“唯一”单词

如何创建一个函数来评估某个x值的用户输入函数的导数

我正在尝试创建一个名为 codechecker 的函数来确定代码是否正确?

创建一个函数来处理我的数据框计算

我可以创建一个过程或函数来删除mysql中的参数表吗?

我想创建一个函数来找到数组中的最大值

我们如何在Keras中创建一个块(可重用的函数集)?

如何创建一个函数来检测缺失数据表示为“-999”,并将其替换为与缺失数据相邻的平均数据

如何创建一个函数来获取特定字符串的前后7个单词?

如何使用两个参数创建一个函数来查找节点是否存在?

创建一个函数来返回一列

如何检测UIScrollView何时可滚动?

我该如何编写一个异步函数来轮询资源,并在资源准备就绪或几秒钟后重试时返回?