视图
健康知识<?php foreach($result as $k => $res): ?>
<?php echo $result[$k]['hlh_url']; ?> <?php echo $result[$k]['title']; ?>![2186f15eb5c70d51255ea1fa1a6d1de3.gif](https://img-blog.csdnimg.cn/img_convert/2186f15eb5c70d51255ea1fa1a6d1de3.gif)
$(function(){
function loadMeinv() {
var url = window.location.href;
$.get(url, {p: count, response: 'ajax'}, function (json) {
console.log(json);
$('#loading').fadeOut(3000);
setTimeout( function(){
if (json.length == 0) {
onOff = false;
return false;
} else {
count++;
}
$.each(json, function (keyList, ovalue) {
var html = '
'+ovalue.hlh_url+''
+'
'+ovalue.title+'';
$minUl = getMinUl();
$minUl.append(html);
});
},1000);
}, 'json');
}
var onOff = true;
var count = 2;
// loadMeinv();
$(window).on("scroll", function () {
$minUl = getMinUl();
if (($(window).scrollTop() >= $minUl.height() - $(window).height()) && onOff && $('#loading').css('display') == "none") {
$('#loading').show();
loadMeinv();
}
});
function getMinUl() {
var $arrUl = $(".p-list");
var $minUl = $arrUl.eq(0);
$arrUl.each(function (index, elem) {
if ($(elem).height() < $minUl.height()) {
$minUl = $(elem);
}
});
return $minUl;
}
});
服务器的代码示例
控制器
/**
* 健康知识
*/
public function healthinfo(){
$data = array();
$page = $this->input->get('p') ? $this->input->get('p'):1;
$response = $this->input->get('response');
$type = "0";
$this->load->model('Xh_client_h5_model');
$data['result'] = $this->Xh_client_h5_model->get_healthinfo($type,$page);
if($response == 'ajax'){
echo json_encode($data['result']);die();
}
$this->load->view('healthinfo',$data);
}
模型
/**
* 获取健康知识的信息
* @param string $type 健康知识 0
* @param string $page
* @return 健康信息的列表
*/
public function get_healthinfo($type,$page){
$healthinfo = array();
$limit = 7;
$offset = ($page - 1) * $limit;
$this->db->where('type',$type);
$this->db->limit($limit, $offset);
$query = $this->db->get('hlh_message');
$row = $query->result_array();
foreach($row as $k=>$v){
$healthinfo[$k]['id'] = $v['id'];
$healthinfo[$k]['title'] = $v['title'];
$healthinfo[$k]['hlh_url'] = $v['hlh_url'];
$healthinfo[$k]['jump_url'] = $v['jump_url'];
}
return $healthinfo;
}