我尝试着按照@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());
});
});
这是我插入的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;
}
}
我仅仅改变了这个演示代码里的一件事情,就是我把$('.table')
定义为$tableClass
而不是$table
,因为我之前已经定义了var $table
为$('#table')
。非常感谢您的帮助!
css
来做吗?为什么要克隆
然后再插入等等呢? - Guruprasad J Raoboostraptable
插件会在表格之前添加一些额外的divs
以使其具有响应性,并且您需要尝试将其附加到确切的位置!也就是说,您所看到的示例使用新创建的table
隐藏了第一个标题和列,这非常难以实现!不管怎样!我会尝试一次! - Guruprasad J Rao