简体   繁体   English

浮动div周围的昏暗区域

[英]Dim area around floating div

I am pretty good at html and css, but horrible at Javascript. 我非常擅长html和css,但是在Javascript方面却很糟糕。

This is the HTML coding I have: 这是我的HTML编码:

<script>
var toggle = function() {
var mydiv = document.getElementById('nodate');
if (mydiv.style.display === 'block' || mydiv.style.display === '')
mydiv.style.display = 'none';
else
mydiv.style.display = 'block'
}
</script>

<div id="nodate" style="display:none"><span class="A"> <input type="image" src="http://www.weebly.com/uploads/1/6/7/6/16768236/custom_themes/307429121386408805/files/close-icon.png?1384992227202" width="42" onclick="toggle();" /></span><b>There are no reservations listed under the date you selected. </b>Please select another date or ask for assistance.<br><br><image src=”http://www.weebly.com/uploads/1/6/7/6/16768236/custom_themes/307429121386408805/files/sorry.jpg?1384992565622” width=”200”/></div>

This CSS code goes along with it: 此CSS代码与之一起:

#nodate {
background-color: #fff;
width: 95%;
height-min: 300px;
z-index: 500;
border: 2px solid #000;
padding: 10px;
margin-left: auto;
margin-right: auto;

position:absolute;
top: -10px;
left:0;
right:0;
margin-left:auto;
margin-right:auto;
}


.A {
float: right;
margin-top: -30px;
margin-right: -30px;
}

When the dIV is launched, it covers a portion of the page but I want it to dim the area surrounding it. 启动dIV后,它会覆盖页面的一部分,但是我希望它使周围的区域变暗。 What is the simplest way and how do I do it (if using Javascript, please help me out) 最简单的方法是什么,怎么做(如果使用Javascript,请帮帮我)

Sounds to me like you're trying to build a modal pop up. 在我看来,您正在尝试构建模式弹出窗口。

You could build that yourself in Javascript of course, but my advice would be to investigate a library to do it for you. 您当然可以使用Javascript来构建它,但是我的建议是研究一个图书馆来为您做。

jQuery is a good choice, and jQuery UI comes with a dialog box which will do exactly what you want. jQuery是一个不错的选择,并且jQuery UI带有一个对话框,可以完全满足您的要求。 It's quite straightforward, and being jQuery, you'll be able to find plenty of help online. 它非常简单,使用jQuery,您将能够在线找到大量帮助。

http://jqueryui.com/dialog/#modal http://jqueryui.com/dialog/#modal

The question you have asked seems not be related to the JavaScript. 您提出的问题似乎与JavaScript没有关系。 The JavaScript code in the question only shows the element, how the element looks like and where it is placed is specified by the corresponding CSS rules. 问题中的JavaScript代码仅显示元素,元素的外观以及放置位置由相应的CSS规则指定。 So we f you quite OK with the HTML and CSS it is better to position the element accordingly, then hide it and display using the JavaScript code. 因此,对于HTML和CSS来说,您还可以,最好相应地放置元素,然后隐藏它并使用JavaScript代码显示。

Why do you need JAVA? 为什么需要JAVA?

For stuff on CSS fading check this out 有关CSS褪色的内容,请查看

click here :P 点击这里:P

Or maybe start thinking more like this 或者也许开始这样思考

#page-cover {
display: none;
position: fixed;
width: 100%;
height: 100%;
background-color: #000;
z-index: 999;
top: 0;
left: 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM