var chordColors = {A:{r:204,g:204,b:238},"A#":{r:204,g:204,b:255},B:{r:204,g:238,b:204},C:{r:204,g:238,b:238},"C#":{r:204,g:255,b:255},D:{r:238,g:204,b:204},"D#":{r:255,g:204,b:204},E:{r:238,g:204,b:238},F:{r:238,g:238,b:204},"F#":{r:255,g:255,b:204},G:{r:238,g:238,b:238},"G#":{r:255,g:255,b:255},N:{r:255,g:255,b:255}}; window.addEventListener('load', function() { var songleWidgetElement = SongleWidgetAPI.createSongleWidgetElement({ api: "songle-widget-api-example", url: "www.youtube.com/watch?v=yIQDGwyJpSo", songAutoPlay: '0', songleWidgetSizeW: 'auto', videoPlayerSizeW: 'auto', videoPlayerSizeH: 'auto', }); document.body.appendChild(songleWidgetElement); }); // Songle Widget の準備が完了すると window.onSongleWidgetReady が実行される window.onSongleWidgetReady = function(apiKey, songleWidget) { var el = songleWidget.rootElement; // ビートに合わせてプレーヤを脈動させる songleWidget.on("beatPlay", function(event) { el.setAttribute('class', 'beat-' + event.beat.position); }); // コード進行に応じて背景色を変える songleWidget.on("chordEnter", function(event) { var color = chordColors[event.chord.name.match(/^([A-GN#]{1,2})/)[1]]; if (color) { document.body.style.backgroundColor = 'rgb(' + [color.r, color.g, color.b].join(',') + ')'; } }); };
<script src="http://widget.songle.jp/v1/api.js"></script>
@keyframes first-beat { 0% { transform: scale( 1.4 ); } 20% { transform: scale( .75 ); } 50% { transform: scale( 1 ); } } @keyframes other-beat-2 { 0% { transform: scale( 1.1 ); } 20% { transform: scale( .85 ); } 50% { transform: scale( 1 ); } } @keyframes other-beat-3 { 0% { transform: scale( 1.1 ); } 20% { transform: scale( .85 ); } 50% { transform: scale( 1 ); } } @keyframes other-beat-4 { 0% { transform: scale( 1.1 ); } 20% { transform: scale( .85 ); } 50% { transform: scale( 1 ); } } div.beat-1 { animation: first-beat 0.5s; } div.beat-2 { animation: other-beat-2 0.5s } div.beat-3 { animation: other-beat-3 0.5s } div.beat-4 { animation: other-beat-4 0.5s }