固定table第一列

表格:为外层div绑定scroll事件

       <div id="freezing" style="overflow:scroll" οnscrοll="javascript:freezing()">
            <table id="timetable">
                <thead>
                <tr id="tablehead">
                    <th></th>
                </tr>
                </thead>
                <tbody id="tablebody">

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

css:设置tr的第一个子元素为相对定位

tr>:first-child{
    width : 66px;
    position : relative;
    border : solid #A4D3EE 1px;
}
js:

//固定表格首列
function freezing(){
    $("tr>:first-child").css("left",$("#freezing").scrollLeft()-1);
    var thWidth=$("#tablehead>:first").width();
    var step=thWidth/5;//分5次过渡,每step像素过渡一次
    var scroLeft=$("#freezing").scrollLeft(); //向左滚动的距离
    var tol=Math.ceil(scroLeft/step);
    if(scroLeft==0){
        $("tr>:first-child").removeClass("isScrolling").css("opacity",1);
    }else if(scroLeft>0&&scroLeft<thWidth){
        $("tr>:first-child").addClass("isScrolling").css("opacity",0.2*tol);
    }else{
        $("tr>:first-child").addClass("isScrolling").css("opacity",1);
    }
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值