I have a video player in a div element. I want to disable everything except the DIV. One way to do it is using lightbox, but I was wondering if I could do it using plain HTML/Javascript.
-
1You might wanna show us some code here? – Severin Mar 07 '14 at 12:18
-
Errrrrmmmmm, what exactly do you want to do here?? – Fizor Mar 07 '14 at 12:19
-
1Create masked div, place it a z-index over 9000 et voila – DarkBee Mar 07 '14 at 12:19
-
you can use css class for that – Ricky Mar 07 '14 at 12:19
4 Answers
I did simple example for you,
jQuery ;
$(".disable").on('click', function(){
// * = select All, find Div, Not (#video) and edit css opacity
$("*").find('div').not("#video").css('opacity', '0.1');
});
HTML ;
<button class="disable">Disable</button>
<div class="header">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div id="video">
<img src="http://fandomania.com/wp-content/uploads/2012/04/06/anarchy01.jpg">
</div>
<div class="footer">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Css ;
.header{border:1px solid #000;background:#cc0000;color:#fff;}
.footer{border:1px solid #000;background:#cc0000;color:#fff;}
Check FIDDLE

- 445
- 5
- 16
-
1just to note this doesn't work for the general case: you end up setting `opacity:0.1` for ancestors of `#video` – Geert-Jan Oct 31 '16 at 18:37
To do this really thoroughly cross-browser, you need an iframe
, which you can create dynamically. Give the iframe
a z-index
higher than anything else on the page except the video div
, make the iframe
the full size of the viewport/page, and then make the video div
a higher z-index
. Now, all clicks except those on the video div
go to the iframe
, which presumably ignores them. You can also use opacity on the iframe if you want to "dim out" the rest of the page.
Very roughly:
function maskAllExcept(div) {
var iframe = document.createElement('iframe');
iframe.style.position = "absolute";
iframe.style.left = iframe.style.right = iframe.style.top = iframe.style.bottom = "0";
iframe.style.zIndex = 1000;
div.style.zIndex = 1001;
document.body.appendChild(iframe);
}

- 1,031,962
- 187
- 1,923
- 1,875
Disable everything except an element and its descendants with Pure CSS. Let's do it with a common HTML dialog
where this behavior could be necessary (you can use a div
if you like)
We just need to add a class to avoid pointer events in all the body
except our dialog
and its descendants.
body.only-dialog *:not(dialog *) { /* not supported yet */
pointer-events: none;
}
Because, :not
only supports a single simple selector, we have to do it like this:
body.only-dialog * {
pointer-events: none;
}
body.only-dialog dialog * {
pointer-events: all;
}
https://jsfiddle.net/bmntvLfs/
Hope this help to future generations :)

- 1,573
- 14
- 23
this may help you
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<div id="popup" class="popup">
<div id="large_map_canvas" style="width:550px; height:550px;" align="right"><iframe align="center" src="your url for video" style="width:545px; height:523px; overflow:hidden;"></iframe></div>
</div>
<a href="javascript:void(0)" onclick="showPopup();">Click to view larger map </a>
</td>
</tr>
</table>
<div id="mainDiv" class="businessDetail-backStyle" style="display:none;"> </div>
<script type="text/javascript">
function showPopup() {
document.getElementById('popup').style.display = 'block';
document.getElementById('mainDiv').style.display = 'block';
}
function hidePopup(){
document.getElementById('popup').style.display = 'none';
document.getElementById('mainDiv').style.display = 'none';
}
</script>
<style type="text/css">
.popup {
position:absolute;
top:0%;
left:37%;
margin:-50px 0 0 -100px;
padding:11px;
display:none;
background:#FFF;
z-index:9999;
}
.businessDetail-backStyle
{
background-color: #333333;
opacity: 90%;
filter:alpha(opacity=90);
background-color: rgba(0,0,0,0.737);
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
color: white;
z-index:999;
}
</style>

- 284
- 1
- 3
- 19