无限滚动不起作用

Infinite scroll isn't working

本文关键字:不起作用 滚动 无限      更新时间:2023-09-26

我一直在学习有关无限滚动的教程,除了我的警报没有被触发并且我无法弄清楚原因之外,一切都完全相同。在 IF 语句中获取滚动位置的任何可能变体也会有所帮助。

<?php
require_once("connect.php");
$results = $connect->query("SELECT * FROM images ORDER BY image_name DESC LIMIT 0,2");
$count = $connect->query("SELECT * FROM images");
$nbr = $count->rowCount();
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <div class='images'>
        <?php
            while($row = $results->fetch())
            {
                ?>
                <p><img src="images/<?php echo $row['image_name'];?>" height="500" width="500"></p>
                <?php
            }
        ?>
        </div>
    <script src='js/jquery.js'></script>
    <script>
        $(document).ready(function(){
        var load = 0;
            $(window).scroll(function(){
                if($(window).scrollTop() == $(document).height() - $(window).height())
                {
                    alert("test");
                }
            });
        });         
    </script>
    </body>
</html> 

找到了解决方案。需要调用正确的库,许多站点没有规定。以下是需要在滚动脚本之前发布的代码。

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>