简体   繁体   English

如果Facebook评论为0,则隐藏div

[英]Hide div if facebook comments are 0

I'm using Facebook social plugin and everything works fine. 我正在使用Facebook社交插件,并且一切正常。 I want to hide the div of my "chat bubble" 我想隐藏“聊天气泡”的div

聊天泡泡

if 如果

<span class="fb-comments-count" data-href="[article URL]"></span>

is zero for each article loaded on my homepage and ofcourse keep the not zero ones. 对于我首页上加载的每篇文章,其值为零,当然请保留不为零的文章。 Also additional information, I'm using a "show more" button to load other articles using ajax as well. 还有其他信息,我也使用“显示更多”按钮来使用ajax加载其他文章。

I already tried using http://graph.facebook.com/ to get the information whether the address contains comments and it worked, but because I needed to ping http://graph.facebook.com/ for each article, my page loading times was abysmal so I removed that. 我已经尝试使用http://graph.facebook.com/来获取地址是否包含注释以及它是否有效的信息,但是因为我需要对每篇文章ping http://graph.facebook.com/ ,所以我的页面正在加载时代很糟糕,所以我删除了那个。

Create a function iterate over span having "fb-comments-count" class. 创建一个具有“ fb-comments-count”类的跨范围迭代的函数。 And find if the text of this span is zero or not. 并查找此范围的文本是否为零。 If it's zero, get the parent of this class(Article DIV) and hide the bubble DIV using hide() method. 如果为零,请获取此类的父级(第DIV条),并使用hide()方法隐藏气泡DIV。

https://api.jquery.com/each/ https://api.jquery.com/each/
//for iterating .fb-comments-count

http://api.jquery.com/text/ http://api.jquery.com/text/
//for getting get count from span

https://api.jquery.com/parent/ https://api.jquery.com/parent/
//to get the parent DIV by class or ID of span

http://api.jquery.com/hide/ http://api.jquery.com/hide/
//to hide the perticular div by class or ID.

Call this function every time you fetch the articles using AJAX. 每次使用AJAX提取文章时都调用此函数。

eg 例如

function yourCustomFunction() {
    $('span.fb-comments-count').each(function(index) {
         var count=$(this).text();
         if(count==0) {
              var parentDiv=$(this).parent('article.yourParentDivClass');

              parentDiv.find('.bubbleDiv').hide();
         }
    });
}

如果没有注释,则将跨度指定为类'fb_comments_count_zero',因此您可以将该样式设置为显示:在样式表中为none

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM