css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
  <video-js id="myPlayerID"
    data-video-id="5068487083001"
    data-account="1752604059001"
    data-player="BJNnLDrfM"
    data-embed="default"
    data-application-id
    class="video-js"
    controls></video-js>

  <script src="https://players.brightcove.net/1752604059001/BJNnLDrfM_default/index.min.js"></script>

  <script src="https://players.brightcove.net/videojs-overlay/1/videojs-overlay.min.js"></script>
            
          
!
            
              @import url("//players.brightcove.net/videojs-overlay/1/videojs-overlay.css");

/* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #fff;
}
/*
 * Styles essential to the sample
 * are below
 */



/* override default styles for overlay */
.videojs .vjs-overlay,
.vjs-overlay.vjs-overlay-top {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-height: 100%;
  margin: auto;
  left: 0;
  top: 0;
  background: none;
}

/* hide the overlay */
.hide-overlay .vjs-overlay {
  display: none;
}
/* hide controls */
.hide-controls.video-js .vjs-control-bar,
.hide-controls .vjs-big-play-button {
  display: none;
}

/* set player size */
.video-js {
  width: 640px;
  height: 360px;
}

/* for the registration form */
/* form layout */
.registration-form {
  font-family: sans-serif;
  font-size: 0.9em;
  color: #333;
}
/* form header */
h1.registration-form {
  font-size: 1.1em;
}
/* buttons */
button.registration-form {
  font-size: 0.8em;
  padding: 0.4em;
  background-color: #234154;
  color: #fff;
  margin: 0.4em;
}
/* divs */
div.registration-form {
  background-color: #f5f5f5;
  opacity: 0.8;
  padding: 0.5em;
}

/* inputs */
div.registration-form input {
  width: 66%;
  display: inline;
}

/* paragraphs */
p.registration-form {
  font-weight: bold;
  margin: 0;
}
            
          
!
            
              videojs.getPlayer('myPlayerID').ready(function() {
  var myPlayer = this,
    // for handling the registration form
    // user info
    firstName,
    lastName,
    emailAddress,
    registered = false,
    // html for the registration form
    overlayContent =
      '<div id="regForm" class="registration-form"><h1 class="registration-form">To view the video, please register or login.</h1><p class="registration-form">First name: <input id="fname" type="text" size="30"></p><p>Last name: <input id="lname" type="text" size="30"></p><p class="registration-form">Email: <input id="email" type="text" size="35"></p><p class="registration-form"><button id="reg" class="registration-form">Register</button><button id="login" class="registration-form">Login</button><button id="noThanks" class="registration-form">No thanks</button></p></div><div id="regPass" class="registration-form" style="display:none;"><p class="registration-form">Choose a password: <input type="password" id="regPassword"></p><p class="registration-form"><button id="submitRegPassword" class="registration-form">Submit</button></p></div><div id="loginPass" class="registration-form" style="display:none;"><p class="registration-form">Enter your password: <input type="password" id="loginPassword"></p><p><button id="submitLoginPassword" class="registration-form">Submit</button></p></div><div id="noThanksMessage" style="display:none;"><p class="registration-form"><strong>Thanks for dropping by anyway!</strong></p></div>';

  // +++ Configure the Overlay +++
  // // add the overlay content
  // change the start value to provide
  // a longer or shorter preview
  myPlayer.overlay({
    content: overlayContent,
    overlays: [
      {
        align: "top",
        content: overlayContent,
        start: 3
      }
    ]
  });

  // +++ Get references to form elements, used in form processing +++
  var fname = document.getElementById("fname"),
    lname = document.getElementById("lname"),
    email = document.getElementById("email"),
    reg = document.getElementById("reg"),
    login = document.getElementById("login"),
    noThanks = document.getElementById("noThanks"),
    noThanksMessage = document.getElementById("noThanksMessage"),
    regForm = document.getElementById("regForm"),
    regPass = document.getElementById("regPass"),
    regPassword = document.getElementById("regPassword"),
    submitRegPassword = document.getElementById("submitRegPassword"),
    loginPass = document.getElementById("loginPass"),
    loginPassword = document.getElementById("loginPassword"),
    submitLoginPassword = document.getElementById("submitLoginPassword");

  // +++ Plays video when form filled out +++
  /**
       * hides the overlay, unhides the controls, and plays the video
       * this function is called from the registration form in the iframe
       * and that is why it is defined in the global scope
       */
  playVideo = function() {
    // hide the overlay, reveal the controls, play
    myPlayer.addClass("hide-overlay");
    myPlayer.removeClass("hide-controls");
    myPlayer.play();
  };

  // +++ Act if preview time is passed +++
  function onTimeupdateHandler() {
    // use my player.currentTime() to get the current position
    // you can't be sure the event will fire at 5 seconds, so check for
    // when the currentTime exceeds 3
    if (myPlayer.currentTime() > 3) {
      myPlayer.pause();
      // we only want to do this once, so unload the listener
      myPlayer.off("timeupdate", onTimeupdateHandler);
      // hide the player controls
      myPlayer.addClass("hide-controls");
    }
  }

  // +++ Check if preview time is passed  +++
  myPlayer.on("timeupdate", onTimeupdateHandler);

  // +++ Process the form +++//
  // decline event listener
  noThanks.addEventListener("click", function() {
    // show the goodbye message
    noThanksMessage.setAttribute("style", "display:block;");
  });

  // register event listener
  reg.addEventListener("click", function() {
    // here you would want to validate the field values
    //
    // show the create password form
    regPass.setAttribute("style", "display:block;");
  });

  // login event listener
  login.addEventListener("click", function() {
    // here you would want to validate the field values
    //
    // show the create password form
    loginPass.setAttribute("style", "display:block;");
  });

  // registration password event listener
  submitRegPassword.addEventListener("click", function() {
    // here you would want to validate the field values
    firstName = fname.value;
    lastName = lname.value;
    emailAddress = email.value;
    password = regPassword.value;

    /* here you would submit the information to your
         * backend registration system and
         * handle the response
         * here we are skipping that and will
         * just set registered to true
         */

    registered = true;

    // invoke the function on the parent page to play the video
    if (registered) {
      playVideo();
    }
  });

  // login password event listener
  submitLoginPassword.addEventListener("click", function() {
    // here you would want to validate the field values
    firstName = fname.value;
    lastName = lname.value;
    emailAddress = email.value;
    password = loginPassword.value;

    // here you would submit the information to your
    // backend authentication system
    // if authentication succeeded,
    // invoke the function on the parent page to play the video
    parent.playVideo();
  });
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console