0
我想缩短ajax响应内的div的高度,.shorten-post
,我不知道如何实现这一点。ajax,缩短Ajax成功的每个div的高度
我只是想缩短那些在Ajax响应,而不是整个文件
,这是目前我的处理AJAX
var page = 1;
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
page++;
loadMoreData(page);
}
});
function loadMoreData(page){
$.ajax(
{
url: '?page=' + page,
type: "get",
beforeSend: function()
{
$('.ajax-load').show();
}
})
.done(function(profcontent)
{
if(profcontent == ""){
$('.ajax-load').html("No more records found");
return;
}
$('.ajax-load').hide();
$(profcontent).filter('.shorten-post').each(function(){
if ($(this).height() > 100) {
$(this).height(50).css({ 'overflow': 'hidden'});
$(this).siblings('.toggle-shorten-post').show();
}});
$(profcontent).insertBefore("#post-data");
})
.fail(function(jqXHR, ajaxOptions, thrownError)
{
alert('server not responding...');
});
}
编辑
这里的脚本是一个总结的代码我的profcontent
<div id="tu_mainpost_<?php echo($current_post['slug_unique']); ?>" class="tu-post">
<div class="tu-post-header">
</div>
<div class="tu-post-image alt-grid shorten-post">
<div class="row">
<img class="img-responsive" src="<?php echo(base_url('assets/img/uploads/' . $current_post['source_img'])); ?>" style="width: 100%; height: inherit;">
</div>
<div class="row">
<div class="col-md-12 tu-main-description" style="margin: 10px 0px;">
<div class="tu-main-description">
<p class="wordbreak"><?php echo nl2br($current_post['description']); ?></p>
</div>
</div>
</div>
</div>
</div>
什么是'profcontent'这里?它是否从服务器呈现内容?当您运行此代码时,您是否也收到任何错误? – sbr
是的,教授内容是来自服务器的渲染内容,并且没有错误。呈现的内容确实会返回,但带有{.shorten-post}类的div不会缩短高度 –
如果可能,请在问题中或codepen/jsfiddle中发布“profcontent”?这可以帮助找到问题。 – sbr