滚动鼠标到底部增加页面内容

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

        .anlition {

            width: 1000px;

            margin: auto;

            border: 1pa solid red;

        }

        .anli {

            width: 100%;

            margin: 25px 0;

            display: flex;

            justify-content: space-between;

        }

        .ok {

            width: 200px;

            height: 300px;

            background-color: rgb(178, 212, 178);

        }

    </style>

</head>

<body>

    <div class="anlition">

        <div class="anli">

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

        </div>

        <div class="anli">

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

        </div>

        <div class="anli">

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

        </div>

    </div>

    <script>

        function over() {

            let timer = null;

            return function () {

                if (timer == null) {

                    timer = setTimeout(() => {

                        let div = document.createElement('div');

                        div.setAttribute('class','anli');

                        div.innerHTML=`<div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>

            <div class="ok"></div>`

            document.querySelector('.anlition').appendChild(div);

                        timer = null;

                    }, 350)

                }

            }

        }

        window.onscroll = over();

    </script>

</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以在el-table中监听一个scroll事件,当滚动底部时触发一个方法,该方法可以通过ajax请求获取第二页的数据,并将其添加到现有的数据列表中。具体实现代码如下: ```html <template> <el-table :data="tableData" @scroll.native="handleScroll"> <!-- 表格列定义 --> </el-table> </template> <script> export default { data() { return { tableData: [], // 存储表格数据 currentPage: 1, // 当前页码 pageSize: 10, // 每页显示的数据条数 total: 0 // 总数据条数 } }, mounted() { // 页面加载时默认加载第一页数据 this.getTableData() }, methods: { getTableData() { // 发送ajax请求获取表格数据 const url = `/api/getTableData?page=${this.currentPage}&pageSize=${this.pageSize}` axios.get(url).then(res => { this.tableData = this.tableData.concat(res.data.list) this.total = res.data.total }) }, handleScroll(event) { const tableBody = event.target.querySelector('.el-table__body-wrapper') const scrollDistance = tableBody.scrollHeight - tableBody.scrollTop - tableBody.clientHeight if (scrollDistance <= 0) { // 滚动底部,加载第二页数据 if (this.tableData.length < this.total) { this.currentPage++ this.getTableData() } } } } } </script> ``` 在上面的代码中,我们监听了el-table的scroll事件,并在handleScroll方法中计算了表格内容区域的滚动距离。当滚动距离为0时,说明已经滚动到了底部,此时我们判断当前是否还有更多数据需要加载,如果还有,则增加当前页码,发送ajax请求获取第二页数据,并将其添加到现有的表格数据中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值