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);
});