How to Mask the mb.YTPlayer background video

Do you need to display your Youtube hosted video as background of your page with a mask that cover part of it?

EFFECT

With the last 3.0 release of my YTPlayer plugin I introduced the ability to create a mask (simply a PNG file) that covers the player giving at the video you are playing a particular effect.

First you need to create your mask; the mask is a an image with transparency saved as png. For example, if you need to create a vignette effect you have to create an image that start from black from the border to degrade to full transparency on the center. You can do that using Photoshop® or any other graphic program you have. The image size should be big enough to fit a HD resolution screen; 1920 x 1080 pixel works quite well. Of course the most the image is complex the most it will be heavy so take things simple.

Here is one of the mask I used for the demo:

MASK2

Now that we have the mask image you just need to setup your background video using the jquery.mb.YTPlayer plugin.

It’s quite simple, just include the jquery.mb.YTPlayer.js javascript and the jquery.mb.YTPlayer.min.css CSS file you find in the dist folder of the plugin package on the head of your HTML page:

Choose the video you want as background of your HTML page and  add a DIV element wherever you want in the page code after the BODY with all the options for the video you want to show:

Now you can add the YTPlayer initialize javascript function just in the HEAD or at the bottom of your page:

As you can see from the code, the YTPAddMask method is invoked just after the initialize function. You can also take advantage of the YTPTime event trigger to change the mask at a specific timestamp:

The methods exposed by the component to manage the mask are:

$.fn.YTPAddMask(“path/to/mask”)
Add a mask to the target video player. If you call the YTPAddMask method while a mask has been already applied the previous mask will be replaced.
For example:

$.fn.YTPRemoveMask()
Remove the previously applied mask from the target video player.
For example:

See the demo    Get the code

And don’t forget to make a donation if you find it useful for your website 😉