js 移動端下拉框加載更多分頁

// 滑動分頁 --重點
$(window).scroll(function () {
    if ($(window).scrollTop() + $(window).height() + 5 > $(document).height()) {
        comment();
    }
});
var isloading=0;  //防止加載多次

//獲取評論
function comment(){

    if (isloading == 0) {
        isloading = 1;//

        var last_page_id= 0;

        var video_id = $('#videoId').val();
        var type = $('#type').val();
        var last_id = $('#last_id').val();

        console.log(video_id);
        console.log(type);
        $.ajax({
            url: '/video_mall/comment/get_comment_list',
            type: 'GET',
            data: {
                video_id: video_id,
                type: type,
                last_id:last_id,
                size:3,
            },
            success: function (res) {
                if(res.code == 1){
                    var str = '';
                    res.data.forEach(function (el,key) {
                        var time = el.create_time;
                        // time = formatUnixtimestamp(time);
                        var date = new Date(time * 1000);
                        var time_date = date.getFullYear()+'-'+date.getMonth()+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes();
                        if(el.head_pic == ''){
                          var head_pic = "/video_mall/new/images/avatar.png"
                        }else{
                            head_pic = el.head_pic;
                        }
                        
                        str +=
                        '<div class="comment-item">'+
                        '    <div class="top-content flex item-center">'+
                        '        <img class="user-avatar" src="' + head_pic + '" alt="">'+
                        '        <div class="comment-time-info flex column">'+
                        '            <p>' + el.user_name + '</p>'+
                        '            <div class="time-box flex">'+
                        '                <span class="date">' + time_date + '</span>'+
                        '            </div>'+
                        '        </div>'+
                        '    </div>'+
                        '    <div class="bot-content">'+
                        '        <div class="content">' + el.content + '</div>'+
                        '        <div class="count-box">'+
                        '            <p class="like-comment" id="like-comment" data-id ="'+ el.id + '" >點贊&nbsp;&nbsp;<span class="like-count-num-'+el.id+'">' + el.like_number + '&nbsp;&nbsp;</span></p>'+
                        // '            <p class="comment-count">評論<span>' + el.comment_num + '</span></p>'+
                        '        </div>'+
                        '    </div>'+
                        '</div>';
                        // if(key == 0){
                            // alert(el.id);
                            last_page_id = el.id;
                            console.log(last_page_id);
                        // }

                    })
                    console.log(last_page_id);
                    isloading = 0;// 0 加載ajax評論 ,1不加載ajax評論

                    if(str){
                        $('.comment-content').append(str);
                        $('#last_id').val(last_page_id);
                        console.log(last_page_id);
                    }else{
                        isloading = 1;
                    }

                }else if(res.code == 0){
                    console.log('沒有數據');
                }
            }
        }) 

    }   
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章