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

              
                <button id="fullscreen">⛶</button>

<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/72199688&amp;color=ff5500&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false"></iframe>

<div class="wavesurfer-transcript">
  <p><span class="wavesurfer-marker" data-start="0" data-end="5">Alien 2347</span></p>
  <p><span class="wavesurfer-marker" data-start="5" data-end="8" data-color="#0000EE">Episode numero 1</span></p>
  <p><span class="wavesurfer-marker" data-start="8" data-end="11.5">Dans le vaisseau A2347,</span> <span class="wavesurfer-marker" data-start="11.5" data-end="15.5">d'étranges extraterrestres complotent secrètement.</span></p>
</div>
              
            
!

CSS

              
                body {
  padding:0;
  margin:0;
  border-sizing: border-box;
}
.wavesurfer-marker:hover {
  cursor: pointer;
  text-decoration: underline;
}

.wavesurfer-marker-current {
  background: rgba(126, 126, 126, 0.4);
}

.region-current {
  font-weight: bold;
}

#subtitles {
  background-color: black;
  margin: auto;
  text-align:center;
  display: flex; /* contexte sur le parent */
  flex-direction: column; /* direction d'affichage verticale */
  justify-content: center; /* alignement vertical */
  font-weight:bold;
  font-size: 5em;
  display: none; /* contexte sur le parent */
  color: white;
}

#subtitles-text {
  padding: 0.5em;
  min-height: 2.5em; /* To allows circle in fix position */
}

#subtitles-playstate {
  position: absolute;
  right: 0;
  bottom: 0;
  transition: 0.3s opacity ease-in;
}

#subtitles-progress{
  position:absolute;
  padding: 0;
  margin: 0;
  bottom:0px;
  width:100vw;
  height: 45px;
  opacity: 0;
  transition: 0.3s opacity ease-in;
}

#subtitles-playstate:hover {
  cursor:pointer;
  opacity: 100!important;
}
              
            
!

JS

              
                "use strict";

console.clear()

var button = document.getElementById("fullscreen");

var sub_div_str = `
  <div id="subtitles"><div>
     <svg height="100" width="100" id="subtitles-top">
    <circle id="subtitles-circle" cx="50" cy="50" r="40" stroke="#FFFFFF" stroke-width="5" fill="white" />
  </svg>
  </div>
  <div id="subtitles-text">Press SPACE to play.<br>Press ESC to escape.</div>
  <div id="subtitles-playstate">⏸</div>
  <div id="subtitles-progress"></div>
</div></div>`;

button.insertAdjacentHTML('afterEnd', sub_div_str);

var subtitles_elm = document.getElementById("subtitles");
var subtitles_text = document.getElementById("subtitles-text");
var subtitles_circle = document.getElementById("subtitles-circle");
var subtitles_playstate = document.getElementById("subtitles-playstate");
var subtitles_progress = document.getElementById("subtitles-progress");

var subtitles_progress_bar = new ProgressBar.Line(subtitles_progress, {
  trailColor: '#1d1d1d',
  color: '#FFFFFF',
  svgStyle: {width: '100%', height: '100%'}
});

button.addEventListener('click', () => {
	if (screenfull.enabled) {
		screenfull.toggle(subtitles_elm);
    document.activeElement.blur();
	}
});

screenfull.on('change', () => {
  if( subtitles_elm.style.display === 'flex') {
    subtitles_elm.style.display = 'none';
  } else {
    subtitles_elm.style.display = 'flex';
    /* Hide cursor if doesn't move*/
    var timer;
    var fadeInBuffer = false;
    subtitles_elm.addEventListener('mousemove', (e) => {
      // Show bar
      if(window.innerHeight-e.clientY < 45 ) {
        subtitles_progress.style.opacity = 100;
      } else {
        subtitles_progress.style.opacity = 0;
      }
      
      
        if (!fadeInBuffer) {
            if (timer) {
                clearTimeout(timer);
                timer = 0;
            }
            subtitles_elm.style.cursor = ''
        } else {
            subtitles_elm.style.cursor = 'default'
            fadeInBuffer = false;
        }
        timer = setTimeout(function () {
            subtitles_elm.style.cursor = 'none'
            fadeInBuffer = true;
        }, 2000)
    });
    subtitles_elm.style.cursor = 'default'
  }
});

// On Ready
document.onreadystatechange = () => {
  if (document.readyState === 'complete') {

    // Create SoundCloud Player Object ( TODO: all loop)
    var iframes = Array.from(document.querySelectorAll('iframe'));
    iframes.forEach(function(iframe, i) {
      var source = new URL(iframe.getAttribute('src')).host;
      
      if( source === 'w.soundcloud.com') {
        var widget = SC.Widget(iframe);
        // NOTE: No need for sanitization for soundcloud player ?
        widget.getDuration( function(duration) {
            DrawTimeline(duration/1000, widget, iframe)
        });
      } else if ( source === 'www.youtube.com' ) {
        var player = new YT.Player(iframe, {
          events: {
            'onStateChange': onPlayerStateChange
          }
        })
      }
    
    });

  } // Document Complete
}; // Document Ready State Change

// Sample Markers on Page
function MarkersInit(elm) {
  var markers = [];
  var elements = Array.from(elm.querySelectorAll('.wavesurfer-marker'));
  elements.forEach(function(el, i) {
    let marker = {};
    marker.time_start = parseFloat(el.dataset.start);
    marker.time_end = parseFloat(el.dataset.end);
    marker.color = el.dataset.color ? el.dataset.color : 'grey';
    marker.duration = marker.time_end - marker.time_start
    marker.name = el.innerText;
    marker.dom = el;
    markers.push(marker);
  });
  return markers
}

// Draw timeline from duration in seconds and markers
// Markers are JSON else there is DataClone error
function DrawTimeline( duration, widget, iframe ) {
  // Init Markers
  var timeline = iframe.nextElementSibling;
  
  // if(timeline.classList[0] !== 'timeline') return false;
  
  var markers = MarkersInit(timeline);

  /*markers.forEach(function(e, i){
    e.dom.style.backgroundColor = e.color
    e.dom.style.width = e.duration / duration * 100 + "%"
  })*/
  
  // Register On Click Event Handler
  var elements = Array.from(timeline.querySelectorAll('.wavesurfer-marker'));
  elements.forEach(function(el, i) {
    el.onclick = function() {
      // Get Data Attribute
      var pos = el.dataset.start * 1000;
      // Seek
      widget.seekTo(pos);
    }
  });
   
  subtitles_elm.onclick = function() {
    widget.toggle();
  }
  
  document.body.onkeyup = function(e){
    if (screenfull.enabled) {
      if(e.keyCode == 32) {widget.toggle()};
      if(e.keyCode == 39 ) {
        widget.getPosition(function(current_time) {
          widget.seekTo(current_time + 5000)
        });
      }
      if(e.keyCode == 37) {
        widget.getPosition(function(current_time) {
          widget.seekTo(current_time - 5000)
        });
      }
    }
  }
  
  widget.bind(SC.Widget.Events.PAUSE, function() {
    subtitles_playstate.style.opacity = 100
    subtitles_playstate.innerHTML = "⏸"
  });
  widget.bind(SC.Widget.Events.PLAY, function() {
    subtitles_playstate.style.opacity = 0
    subtitles_playstate.innerHTML = "▶"
  });
  
  // Bind Continuous Play
  widget.bind(SC.Widget.Events.PLAY_PROGRESS, function() {
    widget.getPosition(function(current_time) {
      current_time = current_time / 1000;
      widget.getDuration(function(duration){
          subtitles_progress_bar.set(current_time * 1000 / duration);
      })
      var none = false;
      markers.forEach(function(marker, i) {
        if (current_time >= marker.time_start && current_time < marker.time_end) {
          marker.dom.classList.add("region-current");
          subtitles_text.innerHTML = marker.dom.innerHTML;
          subtitles_circle.style.fill = marker.color;
          none = true;
        } else {
          marker.dom.classList.remove("region-current");
        }
        if ( none === false ) {
          subtitles_text.innerHTML = "";
          subtitles_circle.style.fill = "white";
        }
      });
    });
  });
  
}
              
            
!
999px

Console