Javascript 通过ajax嵌入Facebook视频-调整大小问题
对于视频库,我使用AJAX加载来自不同视频主机的视频,如FB、Youtube、Vimeo等。我嵌入FB视频,如使用FB的JS SDK中所述 问题是,当我通过AJAX请求FB视频时,视频会调整到更小的尺寸,如下所示: 完全重新加载页面时没有问题(没有AJAX) JS代码片段:Javascript 通过ajax嵌入Facebook视频-调整大小问题,javascript,jquery,ajax,facebook,video,Javascript,Jquery,Ajax,Facebook,Video,对于视频库,我使用AJAX加载来自不同视频主机的视频,如FB、Youtube、Vimeo等。我嵌入FB视频,如使用FB的JS SDK中所述 问题是,当我通过AJAX请求FB视频时,视频会调整到更小的尺寸,如下所示: 完全重新加载页面时没有问题(没有AJAX) JS代码片段: $.ajax({ url: "index.php?gallery&type=fbVideoCode&url=" + url, success:
$.ajax({
url: "index.php?gallery&type=fbVideoCode&url=" + url,
success: function(response) {
response = $.trim(response);
$('span.carousel').replaceWith(response);
FB.XFBML.parse(); // To re-parse all FB videos on the page
}
});
请帮忙
提前感谢。这将使来自Youtube和Vimeo的所有视频响应:
// Find all YouTube videos
var $allVideos = $("iframe[src^='//player.vimeo.com'], iframe[src^='//www.youtube.com']"),
// The element that is fluid width
$fluidEl = $("body");
// Figure out and save aspect ratio for each video
$allVideos.each(function() {
$(this)
.data('aspectRatio', this.height / this.width)
// and remove the hard coded width/height
.removeAttr('height')
.removeAttr('width');
});
// When the window is resized
$(window).resize(function() {
var newWidth = $fluidEl.width();
// Resize all videos according to their own aspect ratio
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.data('aspectRatio'));
});
// Kick off one resize to fix all videos on page load
}).resize();
摘自问题在于我使用的旋转木马的CSS 发布其他人的FB视频代码:-) PHP:(用于AJAX请求) 函数getFBEmbedPlayer($video\u id,$width=600){ 返回“ "; } JS:
$.ajax({
url: "index.php?gallery&type=fbVideoCode&url=" + url,
success: function(response) {
response = $.trim(response);
$('span.carousel').replaceWith(response);
FB.XFBML.parse(); // To re-parse all FB videos on the page
}
});
按照中的说明操作问题在于旋转木马的CSS。谢谢你给我关于浏览器大小调整的想法。我只是在IDE中单独处理JS,我的愚蠢