|
本文实例讲述了thinkPHP实现瀑布流的方法。分享给大家供大家参考。具体分析如下:
很多人都想做瀑布流的效果,这里告诉大家官网使用的方法,首先要下载瀑布流的插件jquery.masonry.min.js 地址:http://masonry.desandro.com/index.html里面包含的很多示例.
流程:
1. 页面初始化时,调用插件进行一次排版;
2. 当用户将滚动条拖到底部时,用ajax加载一次数据,并排版显示
3. 重复2,直到无数据
Html代码:
[U]复制代码[/U] 代码如下:
Insert title here
body {margin:40px auto; width:800px; font-size:12px; color:#666;}
.item{
border: 1px solid #D4D4D4;
color: red;
margin: 0 10px 10px 0;
padding: 10px;
position: relative;
width: 200px;
}
.loading-wrap{
bottom: 50px;
width: 100%;
height: 52px;
text-align: center;
display: none;
}
.loading {
padding: 10px 10px 10px 52px;
height: 32px;
line-height: 28px;
color: #FFF;
font-size: 20px;
border-radius: 5px;
background: 10px center rgba(0,0,0,.7);
}
.footer{
border: 2px solid #D4D4D4;
}
瀑布流下来了
加载中,请稍后...
我是页脚
Action代码:
[U]复制代码[/U] 代码如下://初始化的数据
public function lists(){
$data = D('Info')->order('id DESC')->limit(10)->select();
$this->assign('data', $data);
$this->display();
}
//获取一次请求的数据
public function getMore(){
//获取最后一个id
if(!emptyempty($_GET['lastid']))$map['id'] = array('lt', $_GET['lastid']);
$data = D('Info')->where($map)->order('id DESC')->limit(10)->select();
$this->ajaxReturn($data);
}
注意:通过判断窗口是否滚动到页面底部来决定用ajax加载一次数据,如果不做处理,会一下子请求很多次,所以,要使用条件来限制.
这里使用的是往一个元素上赋值 $("#loading").data("on", true);,在请求期间判断是true则不继续请求,然后在页面请求完成后再赋值为false.
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。
您可能感兴趣的文章:Thinkphp搭建包括JS多语言的多语言项目实现方法ThinkPHP模版中导入CSS和JS文件的方法ThinkPHP实现动态包含文件的方法ThinkPHP添加更新标签的方法ThinkPHP中url隐藏入口文件后接收alipay传值的方法完美解决thinkphp验证码出错无法显示的方法ThinkPHP通过AJAX返回JSON的两种实现方法ThinkPHP中使用ajax接收json数据的方法ThinkPHP打开验证码页面显示乱码的解决方法thinkphp3.2.2实现生成多张缩略图的方法
|
|