首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Containing DIV to "cover“包含的元素

Containing DIV to "cover“包含的元素
EN

Stack Overflow用户
提问于 2016-07-24 14:31:41
回答 1查看 64关注 0票数 1

我的HTML如下所示:

代码语言:javascript
复制
<div id="cover" on-tap="_overlayTapped" class$="{{status}}">
  <form method="POST" action="/some/action">
    <input required id="name" name="name" label="Your name"></input>
    <input required id="surname" name="surname" label="Your name"></input>
    <button type="submit">Click!</button>
  </form>
</div>

我想添加Javascript或样式,这样div #cover将:

1)模糊其内容。例如,当表单加载(通过AJAX)一些默认值时,我希望包含的内容是“模糊的”(我猜是由于#container的不透明),但我也不希望人们能够点击字段。

2)将#cover变成某种“模式”,这意味着点击它将有效地等待一次点击来尝试重新加载数据(如果调用失败)

用一个“包含”的div做这件事实际上是不可能的吗?我意识到,当我点击一个字段时,事件将在字段本身,然后它将冒泡到容器……我是不是搞错了?

EN

回答 1

Stack Overflow用户

发布于 2016-07-24 17:15:18

我不太确定你想做什么,但我为你做了这个,请检查这是不是你想要的。点击按钮打开模式,它的方框将出现,其他内容将被模糊。

代码如下:

代码语言:javascript
复制
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
    modal.style.display = "block";
document.getElementById("blurit").style.filter = "blur(4px)";
    document.getElementById("blurit").style.WebkitFilter = "blur(4px)";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
document.getElementById("blurit").style.filter = "blur(0)";
    document.getElementById("blurit").style.WebkitFilter = "blur(0)";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
document.getElementById("blurit").style.filter = "blur(0)";
    document.getElementById("blurit").style.WebkitFilter = "blur(0)";
    }
}
代码语言:javascript
复制
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
代码语言:javascript
复制
<div id="blurit">
<p>Test it</p>
<img src="https://static.pexels.com/photos/909/flowers-garden-colorful-colourful.jpg" alt="Pineapple" width="500" height="300"><br><br>
<button onclick="myFunction()" id="myBtn">Try it</button>
</div>
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">×</span>
    <p>Some text in the Modal..</p>
  </div>

</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38549395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档