【发布时间】:2018-10-04 18:59:29
【问题描述】:
我试图同时在两个不同的屏幕上垂直滚动,如果一个用户滚动,那么另一个 div 应该自动滚动到第一个 div 上的那个位置。
我遇到的问题是在小屏幕上,底部还有一点空间尝试通过缓慢滚动来查看它。我在我目前尝试过的下面附加代码
var global_std = 0;
var global_tch = 0;
function function_std(){
global_std = $(".scroll_std").scrollTop();
$("#tch_id").scrollTop(global_std);
}
function function_tch(){
global_tch = $(".scroll_tch").scrollTop();
$("#std_id").scrollTop(global_tch);
}
* {
margin: 0px;
padding: 0px;
}
.container {
width: 80%;
background-color: #ccc;
margin: 50px auto;
padding: 20px;
}
.student {
width: 35%;
height: 500px;
float: left;
background-color: white;
overflow-x: scroll;
overflow-y: scroll;
}
.teacher {
width: 60%;
height: 700px;
float: right;
background-color: white;
overflow-x: scroll;
overflow-y: scroll;
}
.clear {
clear: both;
}
.learning-space {
width: 1000px;
height: 1000px;
}
h2 {
margin-bottom: 20px;
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div id="std_id" class="student scroll_std" onscroll="function_std();">
<h2>Student Screen</h2>
<hr>
<div class="learning-space"></div>
</div>
<div id="tch_id" class="teacher scroll_tch" onscroll="function_tch();">
<h2>Teacher Screen</h2>
<hr>
<div class="learning-space"></div>
</div>
<div class="clear"></div>
</div>
【问题讨论】:
标签: javascript jquery html css scroll