Video.js Player Overlay Ad

Certainly many of you have seen Banner Ad centered over video player when you pause playback. This is a simple but effective technique to increase Ads revenue. Unfortunately, such solution cannot be set through player or plugin code. Banner Ad is usually generated by Ad Company on the fly through javascript or iframe object and shows once website HTML interpreted by the browser. So the Ad Banner code must be a part of HTML, not generated by a player.

Still, it is possible to interact with player events and manipulate independent HTML content in any way you want, including Advertising Banner display.

Overlay Banner Ad

In this article we will guide you how to show the overlay Banner Ad centered vertically and horizontally, showing on top of player on each PAUSE event. Provided technique you can use for video.js player with or without Nuevo plugin. You can use it for any other player if it only allows access to video events. You can even use it for native HTML5 player.

First look at player example below.


First, we need 3 new elements with appropriate css style for our overlay banner: main element that covers the entire player object, the second element for Banner Ad and finally some close button. In the example above we use SVG image for a simple close button. See CSS rules:

Code snippet
#my_overlay {
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
#my_overlay .overlay-in {
	transform: translate(-50%, -50%);
#my_overlay .overlay-close {
	width: 28px;
	height: 28px;
	background:url(/images/overlay svg);
	background-size:28px 28px;

Now you can setup video element on the website and insert your Banner Ad code. Remember to wrap it all in one parent div element.

Code snippet
   <video id="player1" class="video-js vjs-fluid vjs-default-skin"  poster="path-to-poster-image" controls preload="auto" playsinline>
      <source src="path-to-video-file" type="video/mp4">
      <source src="path-to-video-file" type="video/webm">
   <div id="my_overlay">
      <div class="oberlay-in">
         // Banner Ad Code Here.
      <div class="overlay-close"></div>

Banner Ad code can be any HTML code, including code from your Ad Company, e.g. javascript or iframe code. In the example above this is iframe from our client's website.

Of course in the end you need some javascript code to interact with player events in order to show and hide Banner Ad. For video.js player with Nuevo plugin first initalize both in standard way and build javascript functions to control Banner Ad object over player element.

Code snippet
//Initialize player and plugin
var player = videojs("player1");
   // possible options list here

// Set relative position for player and overlay parent <div> element
// Get overlay element
var overlay = document.querySelector("#my_overlay");

// Show banner ad on pause event
player.on("pause", function(){
    if (!player.seeking() && player.paused()) {"block";
// Hide banner ad on playing event
player.on("playing", function(){"none";
// Hide banner ad on overlay click (close) and ply video
overlay.onclick = function() {"none";;

In the code example above we simply change overlay "display" status. You can also show/hide overlay with more elegant fade effect using jQuery original functions or a custom javascript fade functions, e.g.


Code snippet
   player.on("pause", function(){
       if (!player.seeking() && player.paused()) {
   player.on("playing", function(){
   $("#my_overlay").click(function() {

On small devices, smaller browser size like a smartphone in portrait mode, the overlay Banner Ad part that exceeds player size is hidden, but close button remains in place and is easy to click in order to hide Banner Ad.

Nuevodevel Blog
Nuevodevel Tweeter