我有一個div元素的視頻播放器。我想禁用除DIV之外的所有內容。一種方法是使用燈箱,但我想知道如果我可以使用純HTML/Javascript來做到這一點。禁用除DIV元素以外的所有內容
2
A
回答
2
我做了簡單的例子給你,
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;}
檢查FIDDLE
+0
只是爲了說明這對於一般情況不起作用:您最終將「opacity:0.1」設置爲「 #video' –
4
要真正徹底地跨瀏覽器,你需要一個iframe
,你可以動態創建。除了視頻div
之外,使iframe
z-index
高於頁面上的其他任何內容,使iframe
爲視口/頁面的完整大小,然後使視頻div
高於z-index
。現在,除視頻div
以外的所有點擊都會轉到iframe
,這可能會忽略它們。如果您想「淡出」頁面的其餘部分,也可以在iframe上使用不透明度。
大致來說:
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);
}
0
這可能會幫助你
<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>
相關問題
- 1. 輕鬆轉換除一個元素以外的所有內容
- 2. 更新所有div元素的內容
- 3. 刪除容器外的所有元素?
- 4. 選擇除一個div的所有元素及其內容
- 5. CSS克隆除div以外的所有內容
- 6. 如何使用jQuery定位除1元素以外的所有內容?
- 7. 除了點擊元素之外,選擇div內的所有其他元素
- 8. 如何禁用頁面的所有元素,除了2 div
- 9. jQuery選擇除了一個元素以外的所有元素
- 10. 如何禁用除所選單元之外的所有單元
- 11. 點擊某個鏈接時,如何去除外部元素和外部元素內的所有內容?
- 12. 從div元素中刪除內容
- 13. jQuery:禁用div內的所有鏈接 - 替換內部內容
- 14. jQuery獲取div內容的文本和元素,但某些元素除外
- 15. 使用外部內容填充div和子div元素
- 16. 抓住div內的所有fieldset元素
- 17. 顯示div內的所有元素?
- 18. VI刪除除模式以外的所有內容
- 19. PHP從陣列中刪除除x以外的所有內容
- 20. PHP刪除除字符串以外的所有內容
- 21. 刪除除VIM中第一列以外的所有內容
- 22. Shell - 刪除除單個文件夾以外的所有內容
- 23. 刪除除元素之外的所有元素
- 24. JQuery .ajax GET適用於除IE以外的所有內容
- 25. 使用Perl剝離除html標籤以外的所有內容
- 26. 使用陣列中除了一個以外的所有元素
- 27. 首先顯示所有<tr>元素,然後隱藏除一個類以外的所有內容
- 28. jQuery - 選擇除了一個div以外的頁面上的所有內容
- 29. 如何編寫xpath以匹配除特定元素以外的所有元素
- 30. 使用Javascript選擇除了一個元素以外的所有元素
你可能想告訴我們這裏的一些代碼? – Severin
Errrrrmmmmm,你到底想做什麼? – Mike
創建被屏蔽的div,將其設置爲超過9000等級的z-index – DarkBee