2016-08-07 14 views
0

Ich habe dieses Video in meinem iframeWie bekomme ich Youtube-Video in jQuery?

<iframe id="Frustrated" width="560" height="315"src="https://www.youtube.com/embed/mjQwedC1WzI" frameborder="0" allowfullscreen sandbox="allow-scripts allow-same-origin"></iframe>

Mit einem üblichen Video, würden Sie so etwas wie

$('#Frustrated').get(0) 

, um das Video zu bekommen und rufen eine Funktion mit ihm.

Wenn ich dies jedoch mit einem YouTube-Video versuche, funktioniert das nicht. Ich habe auf der Google-Entwicklungsseite gelesen, dass man die API einrichten und daraus folgen sollte. Allerdings habe ich API nie verwendet und ich finde die ganze Sache sehr verwirrend.

Dies ist die jQuery, die ich im Moment habe und die ich versuche, Arbeit auf dem iframe zu machen.

jQuery(document).ready(function($) { 
    var video = $('section iframe').get(0); 

    video.onended = function(e) { 
     $('section iframe').animate({ width: "50%"}, 'slow', function(){ 
      $('#information').fadeIn('slow'); 
     }); 
    } 

    video.onplay = function(e) { 
     $('#information').fadeOut('slow', function(){ 
    $('section iframe').animate({ width: "100%" }, 'slow'); 
    }); 
    } 

    $('section iframe').click(function() { 

     if(this.paused || this.ended){ 
      $('#information').fadeOut('slow', function(){ 
      $('section iframe').animate({ width: "100%" }, 'slow', function(){ 
      video.play(); 
      }); 
      }); 
     } 

     else if (this.play) { 
      video.pause(); 
      $('section iframe').animate({ width: "50%" }, 'slow'); 
       $('#information').fadeIn('slow'); 
    } 
    }); 
}); 

Würde jemand erklären können, wie man vorgeht?

+1

Sie haben einige Elemente beteiligt, so die HTML zusammen mit dem jQuery in a [MCVE (** M hinterlassen bitte ** inimal, * * C ** vollständig und ** V ** verifizierbar ** E ** Beispiel)] (http://stackoverflow.com/help/mcve). – zer00ne

Antwort

Verwandte Themen