Scroll down whole browser window

你。 提交于 2019-12-06 05:19:38

The key is using the CSS width:100% & height:100% properties. These will make sure your element is always sized to the full size of your browser. Even when you resize it.

$(document).ready(function() {
  $("#scroll-down").click(function(event) {
    event.preventDefault();
    $('html, body').animate({
      scrollTop: $("#block2").offset().top + 'px'
    }, 'slow');
  })
  $("#scroll-up").click(function(event) {
    event.preventDefault();
    $('html, body').animate({
      scrollTop: $("#block1").offset().top + 'px'
    }, 'slow');
  });
});
html,
body {
  height: 100%;
}
.full-size {
  display: block;
  width: 100%;
  height: 100%;
}
#block1 {
  background-color: red;
}
#block2 {
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrapper full-size">
  <div class="full-size" id="block1">
    <a href="#block2" id="scroll-down">scroll down</a>
  </div>
  <div class="full-size" id="block2">
    <a href="#block1" id="scroll-up">scroll up</a>
  </div>
</div>

EDIT: included JS smoothscroll

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