一行css让页面平滑滚动

图片[1]-一行css让页面平滑滚动
图片[2]-一行css让页面平滑滚动

核心样式

html,body{
    /* 核心属性 让页面平滑滚动*/
    scroll-behavior: smooth;
  }

如果页面中用到了点击锚点跳转到对应的位置,只需要加上上面这个样式即可实现平滑滚动到指定位置。利用它不需要js就可以实现页面置顶的效果,很实用。

代码案例(cv看效果)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      
      html,body{
        /* 核心属性 让页面平滑滚动*/
        scroll-behavior: smooth;
      }
      
      #one,#two,#three{
        width: 80%;
        height: 700px;
        background-color: #eee;
        margin: 50px auto;
        font-size: 50px;
        text-align: center;
        line-height: 700px;
      }
      
      /* 定位置顶按钮 */
      .dTop{
        position: fixed;
        right: 20px;
        bottom: 100px;
        background-color: red;
        text-align: center;
        line-height: 60px;
        width: 60px;
      }
      
      .rightNav{
        position: fixed;
        right: 20px;
        bottom: 200px;
      }
      a{
        display: block;
        text-align: center;
        line-height: 60px;
        width: 60px;
        color: aliceblue;
        text-decoration: none;
        margin-bottom: 10px;
        background-color: skyblue;
      }
    </style>
  </head>
  <body>
    
    <section id="one">模块1</section>
    <section id="two">模块2</section>
    <section id="three">模块3</section>
    
    
    <div class="rightNav">
      <a href="#one">01</a>
      <a href="#two">02</a>
      <a href="#three">03</a>
    </div>
    
    <a href="#one" class="dTop">
      置顶
    </a>
  </body>
</html> 
本站代码模板仅供学习交流使用请勿商业运营,严禁从事违法,侵权等任何非法活动,否则后果自负!
文章版权声明 1 本网站名称: 智码星河
2 本站永久网址:https://wx234.cn
© 版权声明 文章版权归作者所有,未经允许请勿转载。

WX234.CN
喜欢就支持一下吧
点赞6赞赏 分享打赏
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

夸夸
夸夸
还有吗!没看够!
取消
昵称表情代码图片

    暂无评论内容