两个容器之间的镜像滚动效果On.Click
Mirror scrolling effect On.Click between two containers
目前,我正在学习如何在 javascript 和 jquery.I 中编写代码,当您单击导航菜单时,它会向下滚动到特定的 div 内部另一个 div。但是,我试图将这个容器分成两个单独的容器。所以 Left_Container
将从底部开始,而 Right_Container
将从顶部开始。这个想法是在两个容器之间创建一个镜像滚动。当第一个下降时,另一个上升。我假设错误出在 data-target
中的某处,但我的知识不足以自行修复它。如果有人能帮助我,我将不胜感激。
$(document).ready(function() {
$(".Menu li").on('click', function() {
$('.Left_Container').animate({
scrollTop: $($(this).data('target')).position().top + $('.Left_Container').scrollTop()
}, 'slow');
$('.Right_Container').animate({
scrollTop: $($(this).data('target')).position().top + $('.Right_Container').scrollTop()
}, 'slow');
});
});
.Wrapper {
display: flex;
position: relative;
width: 90vw;
height: 90vh;
background-color: purple;
}
.Menu {
position: relative;
width: 10vw;
height: 90vh;
background-color: blue;
}
.Menu li {
position: relative;
font-size: 4vw;
line-height: 5vw;
text-align: center;
color: white;
cursor: pointer;
list-style-type: none;
}
.Left_Container {
position: relative;
width: 43vw;
height: 90vh;
background-color: red;
overflow-y: hidden;
}
.Right_Container {
position: relative;
width: 43vw;
height: 90vh;
background-color: red;
overflow-y: hidden;
}
.Box {
position: relative;
width: 40vw;
height: 90vh;
background-color: purple;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="Wrapper">
<div class="Menu">
<li data-target="#Left_A,Right_C">A</li>
<li data-target="#Left_B,Right_B">B</li>
<li data-target="#Left_C,Right_A">C</li>
</div>
<div class="Left_Container">
<div class="Box" id="Left_C">
Box C
</div>
<div class="Box" id="Left_B">
Box B
</div>
<div class="Box" id="Left_A">
Box A
</div>
</div>
<div class="Left_Container">
<div class="Box" id="Right_A">
Box A
</div>
<div class="Box" id="Right_B">
Box B
</div>
<div class="Box" id="Right_C">
Box C
</div>
</div>
</div>
PS: 先谢谢你了。
此致,
乔治·S.
下面是两个相互反向滚动的 div 的易于理解的示例...
<!DOCTYPE html>
<head>
<style type="text/css">
.BoxStyle {
position: absolute;
left: 10px;
width: 100px;
height: 100px;
overflow: auto;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="BoxStyle" id="Box1" onscroll="Box2.scrollTop=(Box2.scrollHeight-this.scrollTop);">box 1
<div style="position:absolute; top:500px;">.</div>
</div>
<br><br><br><br><br><br><br><br>
<div class="BoxStyle" id="Box2" onscroll="Box1.scrollTop=(Box1.scrollHeight-this.scrollTop);">box 2
<div style="position:absolute; top:500px;">.</div>
</div>
</body>
</html>
目前,我正在学习如何在 javascript 和 jquery.I 中编写代码,当您单击导航菜单时,它会向下滚动到特定的 div 内部另一个 div。但是,我试图将这个容器分成两个单独的容器。所以 Left_Container
将从底部开始,而 Right_Container
将从顶部开始。这个想法是在两个容器之间创建一个镜像滚动。当第一个下降时,另一个上升。我假设错误出在 data-target
中的某处,但我的知识不足以自行修复它。如果有人能帮助我,我将不胜感激。
$(document).ready(function() {
$(".Menu li").on('click', function() {
$('.Left_Container').animate({
scrollTop: $($(this).data('target')).position().top + $('.Left_Container').scrollTop()
}, 'slow');
$('.Right_Container').animate({
scrollTop: $($(this).data('target')).position().top + $('.Right_Container').scrollTop()
}, 'slow');
});
});
.Wrapper {
display: flex;
position: relative;
width: 90vw;
height: 90vh;
background-color: purple;
}
.Menu {
position: relative;
width: 10vw;
height: 90vh;
background-color: blue;
}
.Menu li {
position: relative;
font-size: 4vw;
line-height: 5vw;
text-align: center;
color: white;
cursor: pointer;
list-style-type: none;
}
.Left_Container {
position: relative;
width: 43vw;
height: 90vh;
background-color: red;
overflow-y: hidden;
}
.Right_Container {
position: relative;
width: 43vw;
height: 90vh;
background-color: red;
overflow-y: hidden;
}
.Box {
position: relative;
width: 40vw;
height: 90vh;
background-color: purple;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="Wrapper">
<div class="Menu">
<li data-target="#Left_A,Right_C">A</li>
<li data-target="#Left_B,Right_B">B</li>
<li data-target="#Left_C,Right_A">C</li>
</div>
<div class="Left_Container">
<div class="Box" id="Left_C">
Box C
</div>
<div class="Box" id="Left_B">
Box B
</div>
<div class="Box" id="Left_A">
Box A
</div>
</div>
<div class="Left_Container">
<div class="Box" id="Right_A">
Box A
</div>
<div class="Box" id="Right_B">
Box B
</div>
<div class="Box" id="Right_C">
Box C
</div>
</div>
</div>
PS: 先谢谢你了。
此致,
乔治·S.
下面是两个相互反向滚动的 div 的易于理解的示例...
<!DOCTYPE html>
<head>
<style type="text/css">
.BoxStyle {
position: absolute;
left: 10px;
width: 100px;
height: 100px;
overflow: auto;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="BoxStyle" id="Box1" onscroll="Box2.scrollTop=(Box2.scrollHeight-this.scrollTop);">box 1
<div style="position:absolute; top:500px;">.</div>
</div>
<br><br><br><br><br><br><br><br>
<div class="BoxStyle" id="Box2" onscroll="Box1.scrollTop=(Box1.scrollHeight-this.scrollTop);">box 2
<div style="position:absolute; top:500px;">.</div>
</div>
</body>
</html>