<div id='appendData' class=".col-xs-12">
</div>
<script>
var size = 5;
var startNum = 5;
var end = false;
function getGoodsList(){
$.post('/goods/goodsComment/goods_id/'+<?=$goods_id ?>,
{'startNum' : startNum, 'size' : size},
function(jsonText){
if (jsonText.indexOf('{"GoodsComment":"0"}') == -1){
var obj = JSON.parse(jsonText);
if(obj.GoodsComment.length == undefined){
appendGoodsComment(obj.GoodsComment);
showModel('没有了..');
startNum++;
}else {
for(var i=0;i<obj.GoodsComment.length;i++){
appendGoodsComment(obj.GoodsComment[i]);
startNum++;
}
}
} else {
end = true;
showModel('没有了..');
}
},
'text');
}
$(document).ready(function () {
$(window).scroll(function () {
//$(window).scrollTop() 相对滚动条顶部的偏移 + $(window).height() 窗口高度 == $(document).height()文档总高度 (整个body)
// 延伸至div
// var scrollTop = $(div).scrollTop();//距离顶部
// var scrollHeight = $(document).height();//文档高度
// var windowHeight = $(div).height();//窗口高度
if(($(window).scrollTop() + $(window).height()) == $(document).height() && !end) getGoodsList();
});
});
function appendGoodsComment(goodsComment){
var star = '';
for(var i = 0; i < goodsComment.comment_rank; i++)
star += '<span style="color: orange;" class="glyphicon glyphicon-star"></span>';
var mobile = goodsComment.mobile_phone.substring(0,3)+'****'+goodsComment.mobile_phone.substring(8,4);
var data = '<div style="padding: 10px; background-color: white;margin-bottom: 10px;"><div style="border-bottom:1px solid black; padding-bottom:10px;"><span>'+mobile+'</span>'+
'<span class="pull-right">'+star+'</span></div><div style="padding:10px 0" >'+goodsComment.content+'</div><div class="pull-right">'+goodsComment.times+'</div><div class="clearfix"></div></div>'
$('#appendData').append(data);
}
</script>
Jquery判断滚动条到底部分页加载数据
最新推荐文章于 2022-04-22 17:25:16 发布