Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加内容后没有css样式(使用ajax)_Javascript_Jquery_Css_Ajax - Fatal编程技术网

Javascript 添加内容后没有css样式(使用ajax)

Javascript 添加内容后没有css样式(使用ajax),javascript,jquery,css,ajax,Javascript,Jquery,Css,Ajax,有几十个线程,但在浪费了2天之后,我仍然找不到解决方案:我正在尝试创建一个具有“无限滚动”功能的网站。通过滚动到页面底部,这将触发: $(window).scroll(function() { if($(window).scrollTop() == $(document).height() - $(window).height()) { $.ajax({ url: "loadMoreComments.php?lastComment="+ $(".allvideos:las

有几十个线程,但在浪费了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样式。这是新内容在源代码中的外观(附加后):

样式应用于ids 1-7,但新生成的“图形”(ids 8-10)没有任何样式。即使它们的生成方式与其他对象的创建方式完全相同。我的整个布局都疯了。 有什么解决办法吗?Thx

编辑:
我正在使用这个引导模板:。。。。要生成瓷砖/图形。

请将其作为一个类,而不是使用内联样式,我认为您在代码中遗漏了一些内容

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

尝试以下操作:

$(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);
  }
}
});
}
});

在尝试了很多之后,我发现我的引导模板使用同位素插件来布局瓷砖。正如其纪录片所示(我必须调用特定的同位素方法来添加和重新布局新项目。我必须使用“插入”方法而不是“附加”-不知道为什么,但它有效。4天工作:|

$('#portfolioContainer').isotope( 'insert', $newItems );

您是通过
style
属性设置元素样式的-我假设您是通过JavaScript设置元素样式的,那么您可以发布处理此问题的相关代码吗?如果您有一个CSS文件,其中一个类的样式设置正确,它将应用。动态生成与否,CSS始终应用于DOM。是否有一个Library为前7个ID设置样式标签?我已经阅读并理解了您的问题,但我不知道如何准确回答。我正在使用一个引导模板()为我生成瓷砖/图形。是的,我认为它是由JavaScript@fstanis设计的。但我找不到处理它的相关代码:|