关闭 iframe 周围的指示灯

Turn off the light around iframe

本文关键字:指示灯 周围 iframe 关闭      更新时间:2023-09-26

我有关闭Youtube iframe周围的灯的代码,但它只能在chrome浏览器中正常工作。在 Firefox 中,我可以关灯,但不能再开灯了。知道为什么在火狐中不起作用吗?

代码(或 https://jsfiddle.net/uhL35f15/(:

<html>
<head>
<style>
.video {
position:relative;
z-index:102;
}
#persoff {
background:#000;
opacity:0.9;
filter:alpha(opacity=90);
position:fixed;
left:0;
top:0;
width:100%;
height:100%;
z-index:100;
}
</style>
</head>
<body>
<iframe class="video" width="640" height="360" src="https://www.youtube.com/embed/5HLtpoxOeuM" frameborder="0" allowfullscreen></iframe>
<br><br>
<button class="switch">turn off light</button>
(to turn on light - click somewhere)
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>
var per = 0;
$(document).ready(function(){
  $("#persoff").css("height", $(document).height()).hide();
  $(document).click(function(e) {
    if(($(event.srcElement||e.srcElement).attr('class') != 'switch') && per == 1) {
      $("#persoff").toggle();
      per = 0;
    }
  });
  $(".switch").click(function(){
    $("#persoff").toggle();
    per += 1;
    if (per == 2) {
      per = 0;
    }
  });
});
</script>
<div id='persoff'></div>
</body>
</html>

Firefox 不使用全局event模型,您必须将其作为 hanlder 函数参数完整地传递。

在您的情况下,您已经将其作为e传递。因此,使用e不要在点击处理程序中event

编辑:实际上,在您的情况下,您无法检查event.srcElement,因为在FF事件中undefined

编辑2:所以改用:if(!$(e.target).hasClass('switch') && per == 1)

作为旁注,我不明白你关于变量per逻辑,但这完全偏离了主题。

-

js小提琴-