镜像滚动效果打开.在两个容器之间单击

Mirror scrolling effect On.Click between two containers

本文关键字:两个 单击 之间 滚动 镜像      更新时间:2023-09-26

目前,我正在学习如何用javascript和jquery编写。我使用了一个代码,当您单击导航菜单时,它会向下滚动到另一个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:提前谢谢你。

此致敬意

乔治·

这是一个易于理解的示例,两个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>