CSS suppress screen like Javascript alert

孤人 提交于 2019-12-24 08:51:38

问题


So I have a hidden div that shows itself on $(document).ready() displaying a form to either log in or sign up. I'm trying to get the screen suppressed look as when a traditional Javascript alert is shown. I'm in testing phase and just using a class that sets opacity to the body but it's also applying to the pop-up div. I'm trying to just set opacity to the everything behind it. Here is what I have.

$("body").not("#overlay").addClass("suppress");

I've tried several other variations to exclude that div but I'm not sure it it's possible since I'm applying to the body. Do you have and suggestions to lead me in the right direction?


回答1:


You should set the #overlay div to the following:

#overlay {
     width: 100%;
     height: 100%;
     position:fixed;
     z-index: 1000;
     background: rgba(255, 255, 255, 0.7)
}

The semi-transparent white background overlay will have the same effect as lowering the opacity of the body. Alternatively you could use a 1px by 1px semi-transparent .png background image instead of rgba.

Then you can use another div inside of #overlay which will center the form:

#overlay .inner {
     width: 200px;
     height: 200px;
     position: absolute;
     top: 50%;
     left: 50%;
     margin: -100px 0 0 -100px
}

That way you don't have to worry about altering the css of any other element.


To comment on the approach you mentioned in your answer:

It's my understanding that your current code is saying "find any body element that does not have the id 'overlay' and add the class 'suppress'"... in other words, not() only applies to the set of matched elements. If what you want is to change the opacity of all elements except #overlay, you could do the following:

<body>
     <div id="overlay">
          overlay stuff in here
     </div>

     <div id="other-content">
          All page content in here
     </div>
</body>


$(document).ready(function(){
     $('#other-content').addClass('suppress');  
});


来源:https://stackoverflow.com/questions/8860116/css-suppress-screen-like-javascript-alert

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!