我在这篇文章中关注了@ koala_dev的代码,试图锁定我的表水平滚动的第一列.不幸的是,代码对我的表没有影响.我想知道是否有人可以给我一些关于我做错了什么的指示,因为我是编程新手.
这是我的桌子: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());
});
});
Run Code Online (Sandbox Code Playgroud)
这是我插入的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;
} …Run Code Online (Sandbox Code Playgroud)