我正在尝试在网页上设置无限滚动,我在主页上使用它所有工作精细内容加载良好但当我在类别页面上使用它"我使用accordeon菜单"它没有用,说错了!代码:workscript.js
var page;
var param = location.
search.
slice(location.search.indexOf('?')+1).
split('&');
var result = [];
for(var i = 0; i < param.length;i++) {
var res = param[i].split('=');
result[res[0]] = res[1];
}
if(result['page']) {
page = result['page'];
}
else {
page = 1;
}
$(".pager1").show().text(page);
var block = false;
$(window).scroll(function () {
if($(window).height() + $(window).scrollTop() >= $(document).height() &&
!block) {
block = true;
$(".load1").fadeIn(500, function () {
page++;
$.ajax({
url:"index.php",
type:"GET",
data:"page="+page+"&move=1",
success:function(html) {
if(html) {
$(html).appendTo($("#content")).hide().fadeIn(1000);
$(".pager1").text(page);
}
$(".load1").fadeOut(500);
block = false;
}
});
});
}
});
model.php
function productsbase($category, $start_pos, $perpage){
$query = "(SELECT goods_id, name, img, anons, price, hits, new, sale, date
FROM goodsbase
WHERE goods_brandid = $category AND visible='1')
UNION
(SELECT goods_id, name, img, anons, price, hits, new, sale, date
FROM goodsbase
WHERE goods_brandid IN
(
SELECT brand_id FROM brandsbase WHERE parent_id = $category
) AND visible='1') ORDER BY goods_id LIMIT $start_pos, $perpage";
$res = mysql_query($query);
if (!$res){
exit("<p>WRONG!!!</p>");
}
if(mysql_num_rows($res) == 0) {
exit(false);
}
$productsbase = array();
for($i = 0; $i < mysql_num_rows($res); $i++) {
$productsbase[] = mysql_fetch_array($res,MYSQL_ASSOC);
}
return $productsbase;
}
Controller.php这样
case('catbase'):
$category = abs((int)$_GET['category']);
$perpage = 6;
$start_pos = ($page - 1) * $perpage;
$brandbase_name = brandbase_name($category);
$productsbase = productsbase($category, $start_pos, $perpage);
$meta['title'] = $brandbase_name[0]['brand_name'];
if($brandbase_name[1]) $meta['title'] .= " - {$brandbase_name[1]
['brand_name']}";
$meta['title'] .= " | " .TITLE;
$meta['description'] = "{$brandbase_name[0]['brand_name']},
{$brandbase_name[1]['brand_name']}";
break;
和TOP OF controller.php
if($_GET['page']) {
$page = (int)$_GET['page'];
if(!$page) {
$page = 1;
}
}
else {
$page = 1;
}
$perpage = 6;
$start_pos = ($page - 1) * $perpage;
$productsbase = productsbase($category, $start_pos, $perpage);
if($productsbase && $_GET['move'] == 1) {
foreach($productsbase as $productbase) {
printf("<div class='product-index'>
<div class='Complogo'>
<img src='%simages/Company-logo.png' />
<h2><a href='%sproductbase/%s'>%s</a></h2>
</div>
<div class='product-table-img'>
<a href='%sproductbase/%s'><img class='top' src='%s%s' alt='' /></a>
</div> <!-- .product-table-img -->
<div class='statsbcgbase'><div class='shape'><img src='%simages/larig.png'
/></div>
<p>PRICE:<span>%s</span></p>
</div>
</div>",TEMPLATE,PATH,$productbase['goods_id'],$productbase['name'],PATH,$pr oductbase['goods_id'],PRODUCTIMG,$productbase['img'],TEMPLATE,
$productbase['price']);
}
exit();
}
答案 0 :(得分:0)
JavaScript代码正在更新页面上的.load1
,#content
和.pager1
元素。但是你的PHP模板没有这些元素。
您需要将这些元素添加到您的页面。尝试将以下元素添加到您的页面:
<div class='load1'>
<div id='content'>
<div class='pager1'>
添加这些元素后,脚本应该开始工作。您只需要使其与您的设计正确匹配。