jqueryリストの自動ロードの詳細

4722 ワード

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>{$Think.lang.E160}</title>

<link href="__CSS__/css.css" rel="stylesheet">

<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="black">

<meta name="format-detection" content="telephone=no">

<script src="__JS__/jquery-1.11.1.min.js"></script>

<script>

var cur_page = 1;

var max_page = 0;

var page_size = 15;

     

function get_content(){

    var str = '';

    $.post("__URL__/getSysList", {'size':page_size, 'page':cur_page, 'max_page':max_page}, function(s){

		$('#getMore').hide();

		

		s = $.parseJSON(s);

		

		//          

		if(max_page==0) max_page = parseInt(s.maxPage);

        

        for(i in s.list){

            str +=  '<div class="xttz">'+

					'	<div class="tzyi"><span>'+ s.list[i].sysm_date.date.split(' ')[0] +'</span><b>'+ s.list[i].sysm_title + '</b></div>'+

					'	<div class="tznr">'+ s.list[i].sysm_content +'</div>'+

					'</div>';

        }



		cur_page++;

        $("#list_box").append(str);

    });

}

 



$(function(){

	

	//           ,           

    var con = localStorage.getItem("active_list_con");

    if(con){

        cur_page = localStorage.getItem("active_list_page");

		max_page = localStorage.getItem("active_list_maxpage");

        $("#list_box").append(con);

        $("html,body").scrollTop(localStorage.getItem("active_list_scroll"));

    }else{

		//              

    	get_content();

	}

 

    $(window).scroll(function() {

        if (($(window).scrollTop() || window.scrollY) + $(window).height() == $(document).height() && cur_page != max_page) {

            $('#getMore').show();

            get_content();

             

            //    

            localStorage.setItem("active_list_con", $("#list_box").html());		//        

			localStorage.setItem("active_list_maxpage", max_page);		//       

            localStorage.setItem("active_list_page", cur_page);			//    

            localStorage.setItem("active_list_scroll", $(window).scrollTop());		//      

        }

    });



});

</script>



<link href="__CSS__/common.css" rel="stylesheet" type="text/css">

</head>



<body>

<div class="top"><span><a href="/index.php/Index/Thenews/thenews"><img src="__IMG__/topjt.png" width="70%"></a></span>{$Think.lang.E160}</div>



<div id="list_box"></div>



<div id="getMore" style="position:fixed; left:10%; bottom:0; opacity:0.7; width:80%; height:40px; line-height:40px; border-radius:6px 6px 0 0; background:#fff; color:#000; text-align:center;">        ...</div>



</body>

</html>


 
    //ajax-        

    public function getSysList(){

        //  where  

        $where = "sysm_status=0";

    

        $lang = strtolower(cookie('think_language'))=='en-us' ? 2 : 1;

        $where .= " and sysm_lang={$lang}";

    

        //    

        $page = I('post.page', 1, 'intval');

        $pageSize = I('post.size', 15, 'intval');

        $maxPage = I('post.max_page', 0, 'intval');

        $n = $page * $pageSize;

    

        //   ,          

        if($maxPage==0){

            $count = M()->query("select count(0) as count from SystemMessages where {$where}");

            $max_page = ceil($count[0]['count'] / $pageSize);

        }

    

        $SQL = "SELECT a.sysmid, a.sysm_title, a.sysm_content, a.sysm_date FROM SystemMessages a, (SELECT TOP {$pageSize} sysmid FROM ( SELECT TOP {$n} sysmid FROM SystemMessages WHERE {$where} ORDER BY sysmid DESC ) t ORDER BY t.sysmid ASC ) b WHERE a.sysmid = b.sysmid ORDER BY a.sysmid DESC";

        $list = M()->query($SQL);

        

        $result = ['maxPage'=>$max_page, 'list'=>$list];

        die(json($result));

    }