Javascript 得到位置固定时收缩tr宽度
我有一个数据表,cols是用它的数据自动确定的 但我需要将第一行修改为标题“对于滚动,它仍然固定在顶部”。当我给它Javascript 得到位置固定时收缩tr宽度,javascript,html,css,position,Javascript,Html,Css,Position,我有一个数据表,cols是用它的数据自动确定的 但我需要将第一行修改为标题“对于滚动,它仍然固定在顶部”。当我给它位置:fixed时,标题行的宽度比其他行缩小 设置位置前的第一张图片:固定: 设置位置后:固定: 我无法更改我的结构代码,因为有太多类似的表!!!!只能使用css或javascript 我的代码: <table class="list_row_container"> <tr class="list_row_title">
位置:fixed
时,标题行的宽度比其他行缩小
设置位置前的第一张图片:固定:
设置位置后:固定:
我无法更改我的结构代码,因为有太多类似的表!!!!只能使用css或javascript
我的代码:
<table class="list_row_container">
<tr class="list_row_title">
<td width="30px" align="center"><input type="checkbox" id="keyCheckbox" onclick="updateCheckboxes(this.checked)"></td>
<td>
<a href="index.php?file=file&operation=list&date=asc">تاریخ ثبت</a>
</td>
<td>
<a href="index.php?file=file&operation=list&karbariId=desc">نوع کاربری </a>
</td>
<td>
<a href="index.php?file=file&operation=list&addressMantaghe=desc">آدرس منطقه </a>
</td>
<td>
<a href="index.php?file=file&operation=list&zirBana=desc">زیر بنا </a>
</td>
<td>
<a href="index.php?file=file&operation=list&tabaghe=desc">طبقه</a>
</td>
<td>
<a href="index.php?file=file&operation=list&tedadeOtagh=desc">اتاق </a>
</td>
<td>
<a href="index.php?file=file&operation=list&omreBana=desc">عمر </a>
</td>
<td>
<a href="index.php?file=file&operation=list&ejare=desc">اجاره</a>
</td>
<td>
<a href="index.php?file=file&operation=list&priceTotal=desc">ودیعه </a>
</td>
<td> مشاهده</td>
</tr>
<tr class="list_row_even" id="row492314" >
<td align="center"><input type="checkbox" name="info[rowIds][492314]"></td>
<td class="list_field_container"><span class"list_field_normaltext">1394/02/29</span></td>
<td class="list_field_container"><span class"list_field_normaltext">موقعيت اداري </span></td>
<td class="list_field_container"><span class"list_field_normaltext">.بلوار فردوس غرب پروانه شمالي خ شقايق غربي پ 8</span></td>
<td class="list_field_container"><span class"list_field_normaltext">100</span></td>
<td class="list_field_container"><span class"list_field_normaltext">2</span></td>
<td class="list_field_container"><span class"list_field_normaltext">2</span></td>
<td class="list_field_container"><span class"list_field_normaltext">1</span></td>
<td class="list_field_container"><span class"list_field_normaltext"> -</span></td>
<td class="list_field_container"><span class"list_field_normaltext">660,000,000</span></td>
<td>
<a id="viewmbt-492314" style="cursor: pointer;" title="مشاهده مشاور"><img src="../images/search.png" alt="مشاهده" /></a>
<a id="viewmbt2-492314" style="cursor: pointer;" title="مشاهده مشتری"><img src="../images/groupIcon.png" alt="مشاهده" /></a>
</td>
</tr>
....
这就是解决方案:
$(document).ready(function(){
/// get the td`s width automatically and set inline style width for all tds
$(".list_row_title td").each(function(index){
var index2 = index;
$(this).width(function(index2){
return $(".list_row_container td").eq(index).width();
});
});
$(".list_row_even td").each(function(index){
var index2 = index;
$(this).width(function(index2){
return $(".list_row_container td").eq(index).width();
});
});
///if scroll make fix header tr
var $window = $(window);
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 250) {
$(".list_row_title").addClass('fixed_table_header');
}
else {
$(".list_row_title").removeClass('fixed_table_header');
}
});
});
风格:
.fixed_table_header
{
position: fixed;
top:0;
}
你能更新你的代码吗。添加你的CSS
样式。检查相关问题-,
.fixed_table_header
{
position: fixed;
top:0;
}