may88seiji
7/23/2017 - 12:02 PM

youtube

youtube

$('.youtube').each(function() {
  var movie = $(this).children('iframe'),
      url = movie.attr('src'),
      id = url.match(/[\/?=]([a-zA-Z0-9]{11})[&\?]?/)[1];
  movie.before('<img src="http://img.youtube.com/vi/'+id+'/sddefault.jpg" />').remove();

  $(this).on('click', function() {
    $(this).after('<iframe width="640" height="480" src="https://www.youtube.com/embed/'+id+'?rel=0&amp;autoplay=1" frameborder="0" allowfullscreen></iframe>').remove();
  });
});
/*<div class="youtube">
  <iframe width="640" height="480" src="https://www.youtube.com/embed/動画ID?rel=0&amp;autoplay=1" frameborder="0" allowfullscreen></iframe>
</div>*/