Javascript 相对于具有水平滚动的另一个div移动div
我希望使用Javascript 相对于具有水平滚动的另一个div移动div,javascript,jquery,Javascript,Jquery,我希望使用id=“div2”相对移动div,移动方向与使用id=“div1”移动div滚动条的方向相反 使用jquery或javascript,我想这就是你想要的 <div style="overflow: hidden; position: relative;height: 80px;overflow-x:auto;overflow-y:hidden;width:550px;" id="div1"> <div style="width: 1650px; display
id=“div2”
相对移动div
,移动方向与使用id=“div1”
移动div
滚动条的方向相反
使用jquery或javascript,我想这就是你想要的
<div style="overflow: hidden; position: relative;height: 80px;overflow-x:auto;overflow-y:hidden;width:550px;" id="div1">
<div style="width: 1650px; display: block;">
</div>
</div>
<div style="width: 550px; position: absolute;" id="div2">
</div>
你在找这样的东西吗
<div style="overflow: hidden; position: relative;height: 80px;overflow-x:auto;overflow-y:hidden;width:550px;" id="div1">
<div style="width: 1650px; display: block;">
</div>
<div style="width: 550px; position: absolute;" id="div2"></div>
</div>
jsFiddle示例。太棒了!!最适合我,也是
$('#div2').css('right',$(this.scrollLeft())代码>这也适用于我。
$('#div1').scroll(function() {
$('#div2').css('left', $(this).scrollLeft() * -1);
});