Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <article class="youtube">
  <a id="js-youtube-link" href="" class="youtube-link">
    <div class="youtube-image-wrap">
      <img id="js-youtube-image" src="" class="youtube-image">
      <span id="js-youtube-duration" class="youtube-duration"></span>
    </div>
    <div class="youtube-content">
      <h1 id="js-youtube-title" class="youtube-title"></h1>
      <div class="youtube-detail">
        <span id="js-youtube-channel" class="youtube-channel" data-href=""></span> • <span id="js-youtube-views"></span> 回視聴 • <span id="js-youtube-date"></span>  
      </div>
      <p id="js-youtube-description" class="youtube-description"></p>
    </div>
  </a>
</article>
              
            
!

CSS

              
                .youtube {
  width: 900px;
  margin: 30px auto 0;
}
.youtube-link {
  display: flex;
  text-decoration: none;
  color: #0d0d0d;
  border: 1px solid #0d0d0d;
  transition: opacity .6s;
  &:hover {
    opacity: .7;
  }
}
.youtube-image-wrap {
  position: relative;
  width: 320px;
}
.youtube-image {
  width: 100%;
  vertical-align: top;
}
.youtube-duration {
  display: inline-block;
  position: absolute;
  right: 0;
  bottom: 0;
  color: #fff;
  font-size: 12px;
  background-color: rgba(0, 0, 0, 0.8);
    padding: 2px 6px;
}
.youtube-content {
  flex: 1;
  padding: 10px 20px;
}
.youtube-title {
  font-size: 16px;
}
.youtube-detail {
  font-size: 12px;
  color: #606060;
}
.youtube-channel {
  &:hover {
    color: #0d0d0d;
  }
}
.youtube-description {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  font-size: 14px;
  color: #606060;
}
              
            
!

JS

              
                //リクエストパラメーターのセット
const KEY = 'API_KEYが入ります' ;// APIKEY
const ID = 'fADXsTe05zs' ;// 動画ID
let url = 'https://www.googleapis.com/youtube/v3/videos'; // APIURL
url += '?id=' + ID;
url += '&key=' + KEY;
url += '&part=snippet,contentDetails,statistics,status';

//Ajax通信をする
$(function(){
  $.ajax({
    url: url,
    dataType : 'json'
  }).done(function(data){
    // URL
    $('#js-youtube-link').attr('href', `https://www.youtube.com/watch?v=fADXsTe05zs&t=25s${data.items[0].snippet.channelId}`);
    
    // サムネイル
    $('#js-youtube-image').attr('src', data.items[0].snippet.thumbnails.medium.url);
    
    // タイトル
    $('#js-youtube-title').append(data.items[0].snippet.title);
    
    // チャンネル名
    $('#js-youtube-channel').append(data.items[0].snippet.channelTitle);
    
    // チャンネルURL
	const $youtubeChannel = $('#js-youtube-channel');
    $youtubeChannel.attr('data-href', `https://www.youtube.com/channel/${data.items[0].snippet.channelId}`);
    
    // aタグ内で別のURLに遷移
    $youtubeChannel.on('click', (e) => {
      e.stopPropagation();
      e.preventDefault();
      window.open($('#js-youtube-channel').data('href'), '_blank');
    });
    
    // 再生回数
    $('#js-youtube-views').append(data.items[0].statistics.viewCount);
    
    // 再生時間
    let duration = data.items[0].contentDetails.duration;
    let convertDuration = moment.duration(duration).format('hh:mm:ss');
    $('#js-youtube-duration').append(convertDuration);
    
    // 投稿日時
    moment.locale('ja');
    let date = data.items[0].snippet.publishedAt;
    let convertDate = moment(date).fromNow();
    $('#js-youtube-date').append(convertDate);
    
    // 説明
    $('#js-youtube-description').append(data.items[0].snippet.description);
    
  }).fail(function(data){
    console.log('通信に失敗しました。');
  });
});
              
            
!
999px

Console