list.html 3.1 KB
{extend name="layout/default"}
{block name='content'}
<div class="main">

    <!-- 列表 -->
    <div class="list_item">
        <ul>
            {foreach($list as $l) }
            <li>
                <div class="list_Img"><img src="{$l.image}" alt=""></div>
                <div class="list_Box">
                    <div class="list_Txt txt-cut">{$l.title}</div>
                    <div class="list_Box2">
                        <p class="list_Txt2 ">{$l.desc}</p>
                        <a class="list_Txt3" href="/api/green/index?id={$l.id}&pid={$pid}">[详情]</a>
                    </div>
                </div>
            </li>
            {/foreach}
        </ul>
    </div>
</div>
<script>
    //上拉加载
    var page = 2;
    var data_status = true;
    var pid="{$pid}";
    $('.list_navLi').click(function() {
        $(".list_navdown").show();
        $(this).find('.list_navTxt').addClass('list_active').parents('.list_navLi').siblings().find('.list_navTxt').removeClass('list_active');
    });
    function ajax2(data) {
        ajax("/api/green/getList",data,"post",function (res) {
            var html="";
            if(page==res.msg.last_page){
                data_status=false;
            }else{
                data_status=true;
            }
            var msg=res.msg.data;
            var num=msg.length;
            for(var i=0;i<num;i++) {
                var res = msg[i];
                var image="";
                if(res['image']!=""){
                    image=res['image'];
                }
                var title="";
                if(res['title']!=""){
                    title=res['title'];
                }
                var createtime="";
                if(res['createtime']!=""){
                    createtime=res['createtime'];
                }
                html+='<li>'+
                    '                    <div class="list_Img"><img src='+image+' alt=""></div>'+
                    '                    <div class="list_Box">'+
                    '<div class="list_Txt txt-cut">'+title+'</div>'+
                    '                        <div class="list_Box2">'+
                    '                            <p class="list_Txt2 ">'+createtime+'</p>'+
                    '                            <a class="list_Txt3" href="/api/green/index?id='+res['id']+'&pid={$pid}">[详情]</a>'+
                    '                        </div>'+
                    '                    </div>'+
                    '                </li>';
            }
            $("#huiyuan_List2").append(html);
        },"false");
    }

    function get_data(page) {
        var data = {
            page: page,
            pid:pid
        };
        ajax2(data);
    };
    get_data(page)
    //滚动事件触发
    window.onscroll = function(ev) {
        if (getScrollTop() + getClientHeight() >= getScrollHeight() && data_status) {
            // 后台数据调用
            if (data_status === true) {
                ++page;
                get_data(page);
            }
        } else if (getScrollTop() + getClientHeight() >= getScrollHeight() && !data_status) {
            w("无更多数据")
        }
    };
</script>
{/block}