I was using:
.fb-comments, .fb-comments span, .fb-comments iframe[style] {
width: 100% !important;
}
To make Facebook Comments responsi
Here is a small solution.. try it...
Add this jQuery:
$(document).ready(function(){
$(".fb-comments").attr("data-width", $(".fb-comments").parent().width());
});
Ok this is what I have so far based one Timothy's comment.
function resizeFbComment(){
if (typeof FB === 'undefined')
return;
$(".fb-comments").attr("data-width", $(".fb-comments").width());
FB.XFBML.parse($(".comments")[0]);
}
$(window)
.load(resizeFbComment)
.resize(resizeFbComment);
Obviously, this is a temporary hack. The windows resize should have a timeout.
Below is my solution. This script is just a workaround for this bug
Solution inspired by:
Code below (just replace .comments-area
with your own container class name)
<script>
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
};
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
}
// smartresize
jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
})(jQuery,'smartresize');
$(document).ready(function(){
if ($(".comments-area").width() != document.getElementsByClassName("fb-comments")[0].getAttribute("data-width")) {
$(".fb-comments").attr("data-width", $(".comments-area").width());
}
$(window).smartresize(function(){
if ($(".comments-area").width() != document.getElementsByClassName("fb-comments")[0].getAttribute("data-width")) {
$(".fb-comments").attr("data-width", $(".comments-area").width());
FB.XFBML.parse($(".comments-area")[0]);
}
});
});
</script>
try using this code This might be a little different
#fbcomments, .fb_iframe_widget,
.fb_iframe_widget[style],
.fb_iframe_widget iframe[style],
.fb_iframe_widget span,
#fbcomments iframe [style]
{
width: 100% !important;
}
Adding to the answers here. You really should have a timeout so you're not refreshing the comments dozens of times per second. Also, it's really not great practice to continue crawling the DOM for the elements every time the function is fired, this should be a bit more efficient:
$(function() {
// cache some selectors so we're not looking up divs over and
// over and over on resize
var facebook_comment_resize,
comment_resize_timeout,
$window = $(window),
$comments_container = $('#comments'),
$comments = $('.fb-comments');
var facebook_comment_resize = function() {
// define a function to get the width of the comment container
// then set the data-width attribute on the facebook comment div
$comments.attr("data-width", $comments_container.width());
// Reinitialize the comments so it can grab the new width from
// the data element on the comment div
FB.XFBML.parse($comments_container.get(0));
}
// Set a timeout that can clear itself, keeps the comments
// from refreshing themselves dozens of times during resize
$window.on('resize', function() {
clearTimeout( comment_resize_timeout );
comment_resize_timeout = setTimeout(facebook_comment_resize, 200);
});
// Set the initial width on load
facebook_comment_resize();
});