附加后没有css样式的内容(使用ajax)

时间:2016-10-23 17:23:03

标签: javascript jquery css ajax

有几十个主题但是在浪费了2天后我仍然无法找到解决方案:我正在尝试创建一个具有“无限滚动”功能的网站。通过滚动到页面底部,可以触发:

$(window).scroll(function() {
   if($(window).scrollTop() == $(document).height() - $(window).height()) {  

   $.ajax({
   url: "loadMoreComments.php?lastComment="+ $(".allvideos:last").attr('id') ,
  success: function(html) {

  if(html){       
  $(html).appendTo(".portfolioContainer");

  }
}
});
}
});

...所以我想追加的内容(html)是在“loadMoreComments.php”中生成的。问题是新附加的内容没有应用css样式。这是新内容在源代码中的内容(在追加之后):

sourcecode

样式应用于ID 1-7,但新生成的“数字”(ID 8-10)没有任何样式。尽管它们的生成方式与其他生成方式完全相同。我的整个布局显然都很疯狂。 有解决方案吗THX。

编辑: 我正在使用这个引导程序模板:click ....来生成图块/数字。

3 个答案:

答案 0 :(得分:1)

请使用内联样式,而不是使用内联样式,我认为您错过了代码中的某些内容。

我理解这个问题。 请在添加内容后调用effect-jazz插件。

答案 1 :(得分:1)

试试这个:

$(window).scroll(function() {
   if($(window).scrollTop() == $(document).height() - $(window).height()) {  

   $.ajax({
   url: "loadMoreComments.php?lastComment="+ $(".allvideos:last").attr('id') ,
  success: function(html) {

  if(html){       
  $(html).appendTo(".portfolioContainer");
     var oddStyle = $(".effect-jazz").eq(0).attr("style");
     var evenStyle = $(".effect-jazz").eq(1).attr("style");
     $(".effect-jazz:nth-child(even)").attr("style",evenStyle);
     $(".effect-jazz:nth-child(odd)").attr("style",oddStyle);
  }
}
});
}
});

答案 2 :(得分:1)

经过多次尝试,我发现我的bootstrap模板使用同位素插件来布局瓷砖。正如其纪录片所示(documentary)我必须调用特定的同位素方法来添加和重新布局新项目。我不得不使用“插入”方法而不是“附加” - 不知道为什么但它工作.4天的工作:|

$('#portfolioContainer').isotope( 'insert', $newItems );
相关问题