Jscript代碼
- <script type="text/javascript">
- (function() {
- var pageNo = 2 , PageCount = 3 , toLoad = true;
- window.onload = window.onscroll = function() {
- var ot = document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop,
- ch = document.body.clientHeight,
- och = document.documentElement.clientHeight,
- preCondition = 100;
- flag = ot > ch - och - preCondition;
- if (flag && (pageNo <= PageCount) && toLoad) {
- toLoad = false;
- var loading = document.getElementById('loadding');
- loading.style.display = 'block';
- // var timer = window.setInterval(function(){
- // window.clearInterval(timer);
- $.getJSON('action/do_post.jsp?callback=?', {method: "update",pageNo:pageNo}, function(data) {
- pageNo = data.PageNo + 1;
- PageCount = data.PageCount;
- var msg = data.msg;
- switch (msg) {
- case "success":
- var _html = '';
- for (var i = 0; i < data.posts.length; i++) {
- var voteId = data.posts[i].voteId;
- _html += "<li>";
- _html += "<p>" + data.posts[i].content + "</p>";
- _html += "<i class='vote-counter-'+"+voteId+">" + ${voteService.getCounter(212)}+"</i>";
- _html += "</li>";
- };
- $('#ulList').html($('#ulList').html() + _html);
- break;
- case "offline":
- alert("活動下線,謝謝參與");
- break;
- case "exist":
- alert("重複送出");
- break;
- default:
- alert(msg);
- break;
- };
- toLoad = true;
- });
- // },1000);
- }
- }
- })()
- </script>