我按照@koala_dev 在 这篇文章 中的代码尝试锁定第一列 s 我的表水平滚动。不幸的是,代码对我的表没有影响。我想知道是否有人可以给我一些关于我做错了什么的指示,因为我是编程新手。
这是我的桌子:http: //jsfiddle.net/mademoiselletse/bypbqboe/59/
这是我在 JS 中插入的代码(第 121-133 行):
$(function() {
var $tableClass = $('.table');
// Make a clone of our table
var $fixedColumn = $tableClass.clone().insertBefore($tableClass).addClass('fixed-column');
// Remove everything except for first column
$fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();
// Match the height of the rows to that of the original table's
$fixedColumn.find('tr').each(function(i, elem) {
$(this).height($tableClass.find('tr:eq(' + i + ')').height());
});
});
这是我插入的 CSS 属性(第 36-47 行):
.table-responsive > .fixed-column {
position: absolute;
display: inline-block;
width: auto;
border-right: 1px solid #ddd;
}
@media(min-width:768px) {
.table-responsive>.fixed-column {
display: none;
}
}
The only thing I deviated from the demo code was that I defined $('.table')
as $tableClass
instead of $table
since I have previously defined var $table
as $('#table')
。非常感谢您的帮助!
原文由 Vic 发布,翻译遵循 CC BY-SA 4.0 许可协议
好的..删除你所有的
js
代码,你可以用下面的一些CSS技巧来做到这一点:演示
CSS