应用场景:一般是表头和表体,或者是需要联动的div,滚动一个div的滚动条,让另一个div的滚动条也随之滚动到一样的位置
//表头
<div id="sc-table-head-div" class="sc-table-head-div" style="position:absolute;">
<table id="conitor_head" style="table-layout:fixed;width:100%" cellpadding=0 cellspacing=0>
<colgroup>
<col style="width:24px;text-align:center"/>
<col style="width:24px;text-align:center"/>
</colgroup>
<tr>
<td>序<br/>号</td>
<td style="height:40px">姓名</td>
</tr>
</table>
</div>
//表体
<div id='sc-table-body-div' headid='sc-table-head-div' class='sc-table-body-div' onscroll='scroll(this)' style="overflow:auto">
<table id="conitor_body" style="table-layout:fixed;width:100%"
cellpadding=0 cellspacing=0>
<colgroup>
<col style="width:24px;text-align:center"/>
<col style="width:24px;text-align:center"/>
</colgroup>
<tr>
<td style="height:40px" colspan="1"></td>
<td style="height:40px" colspan="1"></td>
</tr>
</table>
</div>
现在需要我拖动表体的div横向滚动条,让表头也随之移动
<script type="text/javascript">
//给表体的div绑定滚动条事件,
$("#sc-table-body-div").scroll(function(){
//两种方式(一个是属性设置,一二是方法设置)都写上,设置表头div的移动位置未表体的移动位置
try{$("#sc-table-head-div").attr("scrollLeft",$("#sc-table-body-
div").attr("scrollLeft"));}catch(e){}
try{$("#sc-table-head-div").scrollLeft($("#sc-table-body-div").scrollLeft());}catch(e){}
});
</script>
完成
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由半码博客整理,本文链接:https://www.bmabk.com/index.php/post/137543.html