1. 基本知识点:
-
sroll()方法:当用户滚动指定的元素时,会发生 scroll 事件
-
srollLeft():返回或设置匹配元素的滚动条的水平位置
-
scrollTop() ::返回或设置匹配元素的滚动条的垂直位置
案例:A和B绑定同时滚动
<div>
<div class="test">
<div class="A">
A is here!!!
</div>
</div>
<div class="test">
<div class="B">
B is here!!!
</div>
</div>
</div>
.test{
width: 500px;
overflow: auto;
}
// 加载滚动条的相互绑定事件
//A绑定B
$(".A").scroll(function(event){
$(".B").scrollLeft($(this).scrollLeft());
$(".B").scrollTop($(this).scrollTop());
});
//B绑定A
$(".B").scroll(function(event) {
$(".A").scrollLeft( $(this).scrollLeft());
$(".A").scrollTop( $(this).scrollTop());
});