2015-10-19 63 views
-1

我在尝试创建非点击型div时遇到了问题。stopPropagation()停止传播错误

是的,它的繁殖停止,但停​​止什么不应该停止,也不会停止我应该停止

JS

//screen has set stopPropagation 

$("#smokeScreen").click(function(){ 
    event.stopPropagation(); 
}) 

HTML

<div id="content"> 
    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
    <div id="smokeScreen"> 
     <!-- covers whole viewport --> 

     <div id="form"><!-- another form stuff here --></div> 
     <!-- covers whole viewport --> 
    </div> 

    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
</div> 

有趣的是,这段代码让所有的东西都可以点击,除了形式...

那么请,任何提示?

和指针事件:无;在CSS是不是一个解决方案,出于某种原因,它不工作为简单的CSS,我还没有想到为什么,但我需要保持与旧浏览器的兼容性,这是非常新的声明。

+2

'event'没有定义 –

+0

@PranavCBalan雅,在FF –

+0

提供[MCVE](http://stackoverflow.com/help/MCVE)。你绑定了任何“形式”后代事件还是什么? –

回答

1

所以,你看起来在这里丢失的是stopPropagation()防止事件被冒泡到父元素。

不会阻止这些元素或任何兄弟元素被点击。

你需要做的是放置一个覆盖整个屏幕的元素,然后将z-index属性的形式设置为比该元素更高的值,以便它可见(然后应该不需要调用stopPropagation())。

使用你的代码,内联样式,这里有一个例子:

<div id="content"> 
    <div id='smoke_screen' style='z-index: 1000; position: fixed; top: 0; left: 0; bottom: 0; right: 0' /> 
    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
    <div id="smokeScreen"> 
     <!-- covers whole viewport --> 
     <div id="form" style='z-index: 1001'><!-- another form stuff here --></div> 
     <!-- covers whole viewport --> 
    </div> 

    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
    <!-- lots of stuff that has to not be clickable while "smokeScreen is visible" --> 
</div>