document.getElementById("videoElement").onclick = function(ev){
var vid = document.getElementById("videoElement");
var heightOfControls = 50;
// You'll have to figure out a good height to use for your unclickable region where the controls are.
// I used 50 pixels as an example.
var areaAboveControls = vid.height - heightOfControls;
// the layerY attribute of the event lets us know where the mouse was within the topmost layer when the click occurred.
// Using this we can find out where we are in the video and react accordingly.
// Remember that 0 is at the top of the screen on the Y axis, so we need to use greater than to find out if it's BELOW
// our area above the controls.
if(ev.layerY > areaAboveControls)
{
alert("Clicked controls!");
}
else
{
alert("Did not click controls");
// Raise play/pause event from here since the controls won't handle the event and we can safely toggle play/pause.
}
};
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.