Scroll through multiple divs from anchor to anchor

瘦欲@ 提交于 2020-01-16 19:05:23

问题


I have another question. Recently I am trying to build a page with three divs. Each of them has a height of 100vh and a width of 100vw. The thing I want to archive is, that if I am scrolling in div 1 that it automatically scrolls smooth to the top of div 2. And so on. I hope that you understand my question.

div {
  width: 100vw;
  height: 100vh;
}

div:nth-child(odd) {
  background-color: green;
}

div:nth-child(even) {
  background-color: red;
}
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>

回答1:


You can use fullpage.js

new fullpage('#fullpage', {
  scrollOverflow:true
});
.section:nth-child(odd) {
  background-color: green;
}

.section:nth-child(even) {
  background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.0.7/fullpage.min.js" integrity="sha256-e13jRNqOX98m6UAwI/yZTpcDseJtA8s86yfFs4Sqrv8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.0.7/vendors/scrolloverflow.min.js" integrity="sha256-R7CttZ4L0/szai0hbFUlPDiRaEJmqYuvLhyAOr19vQg=" crossorigin="anonymous"></script>

<div id="fullpage">
  <div class="section">Some section</div>
  <div class="section">Some section</div>
  <div class="section">Some section</div>
  <div class="section">Some section</div>
</div>


来源:https://stackoverflow.com/questions/57231813/scroll-through-multiple-divs-from-anchor-to-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!