~遗憾 2022-08-26 07:52 采纳率: 80%
浏览 68
已结题

html5+css+js实现滚轮滚动翻页效果

html5+css+js实现滚轮滚动翻页效果。
纯原生代码,不使用jq。代码越简单越好。

  • 写回答

1条回答 默认 最新

  • 鱼找水需要时间 Java领域优质创作者 2022-08-26 08:56
    关注
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <style>
        .containerBox{
            width: 100%;
            height: 100vh;
            overflow-y: scroll;
        }
        .containerBox::-webkit-scrollbar{
            width: 0;
            height: 0;
        }
        .listItem{
            height: 100px;
            border-radius: 20px;
            margin: 10px;
            background-color: #0db4ff;
            text-align: center;
            color: #ffffff;
        }
    </style>
    <body>
    <div class="containerBox">
       <div class="listItem">1</div>
       <div class="listItem">2</div>
       <div class="listItem">3</div>
       <div class="listItem">4</div>
       <div class="listItem">5</div>
       <div class="listItem">6</div>
       <div class="listItem">7</div>
       <div class="listItem">8</div>
       <div class="listItem">9</div>
       <div class="listItem">10</div>
    </div>
    <script>
        var box = document.querySelector('.containerBox')
        var contentH  = box.clientHeight  //可视区域的高度
        var scrollHight  = box.scrollHeight    //获取全文高度
        var scrollTop  = box.scrollTop    //滚动条的高度
        //监听滚动
        box.onscroll = function(){
           if(contentH - scrollTop- scrollHight -30 <=0.5){
              box.insertAdjacentHTML('beforeEnd',`<div class="listItem">12</div>`)
           }
        }
    
    </script>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月11日
  • 已采纳回答 9月3日
  • 创建了问题 8月26日

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持