首页 > php教程 > php手册 > 正文

【原创】waterfall瀑布流网页实现的设计方案二:KISSY

php中文网
发布: 2016-06-06 20:11:15
原创
1109人浏览过

waterfall瀑布流网页实现的设计方案二:kissy 上一篇介绍了waterfall的设计方案一:Masonry,有需要的请点此查阅. 需求:瀑布流输出,loading 5 次后出现分页,每次loading 12个内容。 jquery虽然不是必须的,但是为了方便,我们还是用上jquery吧。 html+js

waterfall瀑布流网页实现的设计方案二:kissy

上一篇介绍了waterfall的设计方案一:Masonry,有需要的请点此查阅.

需求:瀑布流输出,loading 5 次后出现分页,每次loading 12个内容。

jquery虽然不是必须的,但是为了方便,我们还是用上jquery吧。

ChatPDF
ChatPDF

使用ChatPDF,您的文档将变得智能!跟你的PDF文件对话,就好像它是一个完全理解内容的人一样。

ChatPDF 327
查看详情 ChatPDF

html+js代码:

....
...
...
        loading...
        {desc}
KISSY.use("waterfall,ajax,node,button", function(S, Waterfall, IO,  Node, Button) {
	//loading 5 次,出现分页!
	var loading_times = 5;
	var $ = Node.all;
	//每次loading出现的记录数
	var per_count = 12;
    var tpl = $("'#tpl').html(),
        nextpage = 1,
        waterfall = new Waterfall.Loader({
        container:"#ColumnContainer",
        load:function(success, end) {
            $('#loadingPins').show();
            new IO({
				url:'/lists-ajax-{$catid}-{$page}-'+nextpage+'-'+per_count+'.html',
                dataType: "html",
                success: function(d) {
					//将json字符串变成 json格式数据
					var d =(new Function("","return "+d))();
					// 如果数据错误, 则立即结束
                    if (d.stat !== 'ok') {
                        alert('load data error!');
                        end();
                        return;
                    }
                    // 拼装每页数据
                    var items = [];
                    S.each(d.photos.photo, function(item) {
                        item.height = Math.round(Math.random()*(300 - 180) + 180); // fake height
                        items.push(new S.Node(S.substitute(tpl,item)));
                    });
                    success(items);
					var page_it = (d.photos.page)-(loading_times*({$page}-1));
					// 如果到最后一页了, 也结束加载
					nextpage = page_it + 1;
					if ((nextpage >loading_times)||((nextpage+(loading_times*({$page}-1))) >= d.photos.pages)) {
						if($('.Pager').length==0) {
							$('#wrapper').append(""+d.photos.pages_str+'');
						}
						end();
					}
                },
                complete: function() {
                    $('#loadingPins').hide();
                }
            });
        },
        minColCount:2,
        colWidth:228
    });
});	
    (function ($) {
        var $backEle = $('.backToTop');
        $backEle.click(
			function () {
			    $("html,body").animate({ scrollTop: 0 }, 120);
			})
        $backTOfuc = function () {
            var st = $(document).scrollTop();
            var winH = $(window).height();
            (st > 188) ? $backEle.show() : $backEle.hide();
            if (!window.XMLHttpRequest) {
                $backEle.css("top", st + winH - 166);
            }
        }
        $(window).bind("scroll.backToTop", $backTOfuc);
        $(function () { $backTOfuc(); });
    })(window.jQuery)	
登录后复制

二、php端代码:
lists-ajax-{$catid}-{$page}-’+nextpage+’-’+per_count+’.html
四个参数分别对应:$_GET['catid'],$_GET['page'],$_GET['sub_page'],$_GET['per_page']

...
...
//loading 5 次,出现分页!
$loading_times = 5;
$sub_page = (int)$_GET['sub_page'];
$page = (int)$_GET['page'];
if($page==0) {
	$page = 1;
}
$sub_page = $sub_page+($page-1)*$loading_times;
$limit = (int)$_GET['per_page'];
$catids=implode(',',$array_child);
if($catids!='') {
	$catids.=','.$catid;
}
else {
	$catids=$catid;
}
$sql = "...";
$datas = getRowset($sql,' a.id asc ', $sub_page, $limit,10,$urlrule);
$result['stat']='ok';
$result['photos']['page']=$sub_page;
$result['photos']['pages']=$datas['total_pages'];
$result['photos']['perpage']=$limit;
$result['photos']['total']=$datas['total_count'];
$result['photos']['photo']=$datas['datas'];
$datas_tmp = getRowset($sql,' a.id asc ', $page, $limit*$loading_times,10,$urlrule);
$result['photos']['pages_str']=$datas_tmp['pages_str'];
//$jsonp_callback = $_GET['json_callback'];
echo json_encode($result);die;
登录后复制

全文完。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号