## 加载页面
```
~~~
<div class="info_items" >
{foreach name="infos" item="value" }
<div class="item_one">
<a target="_blank" href="/d{$value['id']}">
<div>
<img class="cate_img" src="{$value['cate_image']}" alt="">
<img class="intro_img" src="{$value['thumb_image']}" alt="">
<p class="title">{$value['title']}</p>
</div>
<div class="intro">
{$value['desc']}
</div>
<div class="intro_user">{$value['user_name']}</div>
<div class="detail_info">
<button class="detail_btn">
查看详情
</button>
</div>
</a>
</div>
{/foreach}
<input type="hidden" id="more_div">
</div>
<input type="hidden" id="offect" value="10" />
<!--加载状态-->
<div class="no-more" id="show_more">没有更多了</div>
~~~
```
## 页面下拉触发事件
~~~
$(window).scroll(
function() {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if (scrollTop + windowHeight == scrollHeight) {
$("#show_more").html('数据加载中');
var offect = $("#offect").val();
var search_val = $(".search_val").text();
var mm = location.href;
var index = mm .lastIndexOf("\/");
var str = mm .substring(index , mm .length);
var url = str;
$.post(url,{offect:offect}, function(data){
console.log(data);
if(data != -1){
var to_array = eval("("+data+")");
var str = "";
console.log(to_array);
for(var p in to_array){
str += '<div class="item_one">\n' +
' <a href="d'+to_array[p].id+'">\n' +
' <div>\n' +
' <img class="cate_img" src="'+to_array[p].cate_image+'"alt="">\n' +
'\n' +
' <img class="intro_img" src="'+to_array[p].thumb_image+ '"alt="">\n' +
' <p class="title">'+to_array[p].title+'</p>\n' +
' </div>\n' +
' <div class="intro">'+to_array[p].desc+'</div>\n' +
' <div class="intro_user">'+to_array[p].user_name+'</div>\n' +
' <div class="detail_info">\n' +
' <button class="detail_btn">\n' +
' 查看详情\n' +
' </button>\n' +
' </div>\n' +
' </a>\n' +
' </div>\n';
}
$("#offect").val(offect*1+10);
$("#more_div").before(str);
}else{
$("#show_more").html('没有更多数据了');
}
}, 'json');
}
});
~~~
## 控制器偏移分页
```
~~~
public function index()
{
$cates = Db::name('category')->where('status', '=', 'normal')->where('pid', "neq", '0')->order('weigh desc')->field('id,name,type')->select();
$category_id = isset($_GET['id']) ? $_GET['id'] : '';
$this->assignconfig('category_id', $category_id);
$where['status_switch']=['=','1'];
//$where['recom_ids']=['in',"'".];
//轮播图
$recm_id = Db::name("recom")->where('recom_name','like','%轮播图%')->field('id,recom_name')->find();
$map[]=['exp',Db::raw('FIND_IN_SET('.$recm_id['id'].',recom_ids)')];
$lunbo = Db::name('artical')->where($map)->where('status_switch','=',1)->field('id,thumb_image')->order(['weigh' => 'desc', 'create_time' => 'desc'])->limit(5)->select();
//中间部分
$mid_id = Db::name("recom")->where('recom_name','like','%最新最热%')->field('id,recom_name')->find();
$map2[]=['exp',Db::raw('FIND_IN_SET('.$mid_id['id'].',recom_ids)')];
$middle = Db::name('artical')->where($map2)->where('status_switch','=',1)->field('id,title')->order(['weigh' => 'desc', 'create_time' => 'desc'])->limit(14)->select();
//右侧图片
$right_id = Db::name("recom")->where('recom_name','like','%首页右侧图片%')->field('id,recom_name')->find();
$map3[]=['exp',Db::raw('FIND_IN_SET('.$right_id['id'].',recom_ids)')];
$right_image = Db::name('artical')->where($map3)->where('status_switch','=',1)->field('id,thumb_image,title')->order(['weigh' => 'desc', 'create_time' => 'desc'])->limit(3)->select();
//右侧标题栏
$right_title01 = Db::name("recom")->where('recom_name','like','%头条%')->field('id,recom_name')->find();
$map4[]=['exp',Db::raw('FIND_IN_SET('.$right_title01['id'].',recom_ids)')];
$right_title_info01 = Db::name('artical')->where($map4)->where('status_switch','=',1)->field('id,title')->order(['weigh' => 'desc', 'create_time' => 'desc'])->limit(4)->select();
$right_title02 = Db::name("recom")->where('recom_name','like','%相关%')->field('id,recom_name')->find();
$map5[]=['exp',Db::raw('FIND_IN_SET('.$right_title02['id'].',recom_ids)')];
$right_title_info02 = Db::name('artical')->where($map5)->where('status_switch','=',1)->field('id,thumb_image,title')->order(['weigh' => 'desc', 'create_time' => 'desc'])->limit(4)->select();
$right_title03 = Db::name("recom")->where('recom_name','like','%推荐%')->field('id,recom_name')->find();
$map6[]=['exp',Db::raw('FIND_IN_SET('.$right_title03['id'].',recom_ids)')];
$right_title_info03 = Db::name('artical')->where($map6)->where('status_switch','=',1)->field('id,thumb_image,title')->order(['weigh' => 'desc', 'create_time' => 'desc'])->limit(4)->select();
$offect = isset($_POST['offect']) ? $_POST['offect'] : 0;
$infos = Db::name('artical')->where('status_switch','=',1)->field('admin_id,mark,status_switch', true)->order(['weigh' => 'desc', 'id' => 'desc'])->limit($offect, 10)->select();
foreach ($infos as &$v) {
$user = Db::name('user')->where('id', '=', $v['user_id'])->field('username')->find();
$cate = Db::name('category')->where('id', '=', $v['category_id'])->field('id,name,image')->find();
$v['user_name'] = $user['username'];
$v['cate_name'] = $cate['name'];
$v['cate_image'] = $cate['image'];
}
if (isset($_POST['offect'])) {
if (!empty($infos)) {
return json_encode($infos);
die;
} else {
return -1;
die;
}
}
$this->assign([
'lunbo'=>$lunbo,
'middle'=>$middle,
'right_image'=>$right_image,
'right_title_info01'=>$right_title_info01,
'right_title_info02'=>$right_title_info02,
'right_title_info03'=>$right_title_info03,
'infos'=>$infos
]);
return $this->view->fetch();
}
~~~
```
##
```
## 搜索功能
```
~~~
public function search($keyword ='' ,$search_word = '')
{
$where = [];
$keywords = '';
if ($keyword !='') {
$_GET['keywords'] = $keyword;
$keywords = $_GET['keywords'];
$where['tag'] = ['like', "%" . $keywords . "%"];
}
if ($search_word!='') {
$_GET['search_keyword'] = $search_word;
$keywords = $_GET['search_keyword'];
$where['tag|title'] = ['like', "%" . $keywords . "%"];
//$where['title'] = ['like',"%".$search_keyword."%"];
}
$where['status_switch'] = ['=', '1'];
$offect = isset($_POST['offect']) ? $_POST['offect'] : 0;
$infos = Db::name('artical')->where($where)->field('admin_id,mark,status_switch', true)->order(['weigh' => 'desc', 'id' => 'desc'])->limit($offect, 10)->select();
foreach ($infos as &$v) {
$user = Db::name('user')->where('id', '=', $v['user_id'])->field('username')->find();
$cate = Db::name('category')->where('id', '=', $v['category_id'])->field('id,name,image')->find();
$v['user_name'] = $user['username'];
$v['cate_name'] = $cate['name'];
$v['cate_image'] = $cate['image'];
}
if (isset($_POST['offect'])) {
if (!empty($infos)) {
return json_encode($infos);
die;
} else {
return -1;
die;
}
}
$this->view->assign('keywords', $keywords);
$this->view->assign('infos', $infos);
return $this->view->fetch();
}
~~~
```