页面锚点滚动3

<ul class="menu">
  <li><a href="#html">html</a></li>
  <li><a href="#css">css</a></li>
  <li><a href="#js">js</a></li>
</ul>
<ul class="body">
  <li id="html">html</li>
  <li id="css">css</li>
  <li id="js">js</li>
</ul>
<style>
  $blue: red;
  $red: #ea7575;
  $green: #83c16f;
  body,
  html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
  }
  html {
    scroll-behavior: smooth;
  }
  ul li {
    list-style: none;
  }
  .menu {
    position: fixed;
    background: #333;
  }
  .menu li {
    float: left;
    width: 100px;
    height: 50px;

    margin-left: 50px;
    text-align: center;
    line-height: 50px;
  }
  a {
    color: #fff;
  }
  .menu:after {
    content: "";
    display: block;
    clear: both;
  }
  .body {
    width: 100%;
    height: 100%;
  }
  .body li {
    height: 100%;
    text-align: center;
  }
  .body li:first-child {
    background: $blue;
  }
  .body li:nth-child(2) {
    background: $red;
  }
  .body li:nth-child(3) {
    background: $green;
  }
</style>
  • 关键部分:
  html {
    scroll-behavior: smooth;
  }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。