我有一个在图库中加载图像的功能。在整个站点中,它会加载最后 20 张图像,然后当用户向下滚动时,它会加载另外 20 张图像并使用无限滚动代码。
但是,在一页上这不起作用,我很困惑为什么不这样做。
我已将问题代码缩小到:
function getEachBoardPins($id,$limit=false)
{
$sql = "SELECT
*
FROM
pins
WHERE
board_id = $id
ORDER BY time DESC";
if($limit)
$sql .=" LIMIT $limit" ;
$query = $this->db->query($sql);
return $query->result();
}
这将加载图库中的每张图片。一些画廊有超过 1000 张图片,因此加载需要很长时间。
通过将第一行中的“$limit=false”值更改为 true,只会呈现最后上传的图像。
任何人都可以帮助我或指出一个好的方向,以便我解决它吗?
谢谢。
编辑:
无限滚动代码:
$(function(){
// alert($('.pin_item').length);
var $alpha = $('#alpha');
$alpha.imagesLoaded( function(){
$alpha.masonry({
itemSelector: '.pin_item',
isFitWidth: true,
isAnimatedFromBottom: true
//isAnimated: true
});
});
$alpha.infinitescroll({
navSelector : '#page-nav', // selector for the paged navigation
nextSelector : '#page-nav a', // selector for the NEXT link (to page 2)
itemSelector : '.pin_item', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: '<?php echo site_url(); ?>/application/assets/images/ajax_loader_blue.gif'
}
},
// trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$alpha.masonry( 'appended', $newElems, true );
$("a.act_uncomment").hide();
$(".enter_comm").hide();
//Examples of how to assign the ColorBox event to elements
$(".group1").colorbox({rel:'group1'});
$(".group2").colorbox({rel:'group2', transition:"fade"});
$(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
$(".group4").colorbox({rel:'group4', slideshow:true});
$(".ajax").colorbox({scrolling:false,transition:"elastic"});
$(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
$(".inline").colorbox({inline:true, width:"50%"});
$(".callbacks").colorbox({
onOpen:function(){ alert('onOpen: colorbox is about to open'); },
onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
});
//Example of preserving a JavaScript event for inline calls.
$("#click").click(function(){
$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
return false;
});
});
}
);
});