2

無限スクロールに jquery.esn.autobrowse.js プラグインを使用しようとしていますが、問題が発生しました。プラグインはすべての画像を一度にロードしています。問題は、ページをスクロールせずにオフセットを更新することにより、javascript が継続的に URL を呼び出しているようです。以下は、HTML および PHP スクリプトです。助けてくれてありがとう。

GalleryPage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.esn.autobrowse.js"></script>
<script type="text/javascript" src="js/jquery.json-2.2.min.js"></script>
<script type="text/javascript" src="js/jstorage.js"></script>
</head>
<body>
 <div id="content">
<div id='gallery'></div>
 <script type="text/javascript">
 $(function () {
        $('#gallery').autobrowse(
            {
                url: function (offset)
                {
                return "getGallery.php?album_id=1&page="
                +Math.round(offset/20);
                },

                template: function (response)
                {
                    var markup='';
                    for (var i=0; i<response.items.length; i++)
                    {
                        markup+='<a href="'+response.items[i].photoID+'"><img src="'+response.items[i].Image+'" /></a>';
                    };
                    return markup;
                },
                itemsReturned: function (response) { return response.items.length; },
                offset: 0,
                max: 10000,
                loader: '<div class="loader"></div>',
                useCache: false,
                expiration: 1

            }
        );
 });
</script>
</div>
</body>
</html>

getGallery.php

<?php

$count=20;
$offset=0;
if (isset($_GET['count'])) $count=$_GET['count']*1;
if (isset($_GET['page']))  $offset=$_GET['page']*$count*1;
$album_id=$_GET['album_id'];
$arr = array();
$sql="SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = $album_id and published=1 ORDER BY orderId LIMIT $offset,$count";
//logToFile('Sql....'.$sql);
$rs = mysql_query($sql);

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}

 echo '{"items":'.json_encode($arr).'}';

?>

logtoFile をオンにして、ファイルに記録されている内容を確認すると...次のように、最初のページの読み込み時に複数の SQL がすべて実行されていることがわかります。

Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 0,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 20,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 40,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 60,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 80,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 100,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 120,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 140,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 160,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 180,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 200,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 220,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 240,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 260,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 260,20
Sql....SELECT photo_id as photoID,thumbnail_location as Image FROM photos WHERE album_id = 1 and published=1 ORDER BY orderId LIMIT 280,20
4

1 に答える 1

0

あなたはそれを解決することができます:

+Math.ceil(offset/20)

それ以外の

+Math.round(offset/20)
于 2016-04-30T06:53:51.427 に答える