<script type="text/javascript">
$(function hook() {
$(window).scrollTop(1);
var self = $("#hook");
$(window).scroll(function() {
var st = $(window).scrollTop();
if (st <= 0) {
self.addClass('show').removeClass('hide');
setTimeout(function tt() {
self.stop();
self.addClass('hide').removeClass('show');
last_id = $("#lp_content").find('.live-cont-lst-main').eq(0).find('.btn-live-lst-box').eq(0).attr('id');
if(last_id==undefined||last_id==''||last_id==null){
last_id=1;
}
$.get("{:U('Live/index',array('lid'=>$live['vid'],'order'=>$order))}", {'type': 'refresh'}, function(json) {
if(json.html!==''){
$('.top-live-lst-box').remove();
$('.live-cont-lst-main').remove();
$('#hook').after(json.html);
//初始化load
window.finished = true;
window.page=1;
}
$(window).scrollTop(1);
}, 'json');
}, 500)
}
})
})
var live_ajax = {
//滚动加载
ajaxload: function(){
var all_page = {$all_page};
window.page = {$page};
window.finished = true;
$(window).scroll(function(){
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if(scrollTop + windowHeight + 100 >= scrollHeight && window.finished){
window.finished = false;
if(window.page+1 > all_page){
window.finished = false;
}else{
$.get("{:U('Live/index',array('lid'=>$live['vid'],'order'=>$order))}", {page:window.page+1}, function(json) {
window.finished = true;
window.page = json.page;
$('#lp_content').append(json.html);
},'json');
}
}
});
}
}
live_ajax.ajaxload();
</script>
controller:
//分页参数
$page = (int) I('get.page', 1);
$pageSize = 10;
$count = $this->LiveProgressModel->getCount($live['id']);
$all_page = ceil($count / $pageSize);
$order ='desc';
//分页[S]
$this->assign('page', $page);
$this->assign('all_page', $all_page);
$this->assign('live',$live);
$this->assign('dayArray',$dayArray);
$this->assign('liveProgress',$liveProgressArrayForDay);
$this->assign('liveTopProgress',$liveProgressTopArrayForDay);
if ($page > 1) {
$last_page=$page-1;
$liveProgress_compare_temp=$this->LiveProgressModel->getList($id,$pageSize * ($last_page - 1),$pageSize * $last_page - 1,$order);
$last_time=$this->_progress_compare_oneDay($liveProgress_compare_temp,$order);
$this->assign('last_time',$last_time);
unset($timeline["$last_time"]);
C('LAYOUT_ON', FALSE);
$html = $this->fetch("ajaxload");
$this->ajaxReturn(array("page"=>$page, "html"=>$html)); exit;
}else{
C('LAYOUT_ON', FALSE);
$html = $this->fetch("ajaxload");
if(I('type')=='refresh'){$this->ajaxReturn(array("page"=>$page, "html"=>$html));exit;}
else{$this->assign('html', $html);}
}
C('LAYOUT_ON', true);
</span>
model:
private $cacheKey = array('jiemian:hash:live_progress_data:', 0);
private $cacheProgress = ['jiemian:zset:live_progress_list:', 0];//直播进度id
/**
* 得到个数
* @param $lid
* @return mixed
*/
public function getCount($lid){
$key = $this->cacheProgress[0].$lid;
if( $this->redis && ($this->redis->exists($key)) ){
$count = $this->redis->zCount($key,"-inf","+inf");
}else{
$SqlWhere ="lid=$lid and status=1 ";
$count = $this->where($SqlWhere)->count();
}
return $count;
}
/**
* 进展的id列表
* @param $lid
* @param int $start
* @param $end
* @return array|bool
*/
public function getList($lid,$start=0,$end=-1,$order='desc'){
if(empty($lid)) return false;
$key = $this->cacheProgress[0].$lid;
if($this->redis && $this->redis->exists($key) ){
if($order=='desc'){$return = $this->redis->zRevRange($key,$start,$end);}
else{$return = $this->redis->zRange($key,$start,$end);}
}else{
$order=$order=='desc'?'desc':'asc';
$result = $this->where(['status'=>1,'lid'=>$lid])->field('id')->order("id $order")->select();
foreach($result as $k=>$v){$this->redis->zAdd($key,$v['id'],$v['id']);}
if($end == -1) $end=count($result);
$returnArray = array_slice($result,$start,$end-$start+1);
foreach($returnArray as $k=>$v){$return[$k]=$v['id'];}
}
return $return;
}</span>