2015-06-18 109 views
1

我已經應用了以下js,以使youtube視頻變得快速響應。 視頻是發生在IFRAME 這裏是腳本 - :YouTube視頻沒有響應

var $allVideos = $("iframe[src^='//player.vimeo.com'], iframe[src^='//www.youtube.com']"), 
 

 
    $fluidEl = $(".newsblock_maintext"); 
 

 
$allVideos.each(function() { 
 

 
    $(this) 
 
    .data('aspectRatio', this.height/this.width) 
 

 
    .removeAttr('height') 
 
    .removeAttr('width'); 
 

 
}); 
 

 
$(window).resize(function() { 
 

 
    var newWidth = $fluidEl.width(); 
 

 
    $allVideos.each(function() { 
 

 
    var $el = $(this); 
 
    $el 
 
     .width(newWidth) 
 
     .height(newWidth * $el.data('aspectRatio')); 
 

 
    }); 
 

 
}).resize();

而且低於自己的YouTube視頻被賦予被放置在「newsblock_maintext」分區。

<div class="newsblock_maintext"><p>Bekijk hier de nieuwe kijk op het wonen volgens MisuraEmme: "The way you are furniture for 24H life-style" zoals onlangs gepresenteerd is, tijdens de succesvolle Salone del Mobile 2015.</p><p><iframe width="560" height="315" frameborder="0" src="https://www.youtube.com/embed/8Ei0jelpeGQ"></iframe></p></div>
這樣,我需要什麼東西,使這個視頻響應。

回答

2

iframe選擇器返回null。您在選擇器中缺少https

$( 「IFRAME [SRC^= '// player.vimeo.com'], IFRAME [SRC^= '// www.youtube.com']」)

變化

var $allVideos = $("iframe[src^='//player.vimeo.com'], iframe[src^='//www.youtube.com']") 

var $allVideos = $("iframe") 

var $allVideos = $("iframe[src^='//player.vimeo.com'], iframe[src^='https://www.youtube.com']") 

工作小提琴:

Fiddle

相關問題