2016-07-24 33 views
1

我有HTML像這樣:包含分區爲 「覆蓋」 包含的元素

<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?我意識到,當我點擊一個領域時,這個事件將會出現在領域本身,然後它會向容器中冒泡......我是否會錯誤地使用它?

+0

兩個要求應該是可能的。你可以包括'css','javascript'試過了嗎? – guest271314

+0

它實際上是一個非常複雜的聚合物元素...這是簡化的版本! – Merc

回答

0

我不是很確定你想做什麼,但我爲你做了這個,請檢查這是你想要的。點擊按鈕打開模式,它會出現,其他內容將變得模糊。

下面是代碼:

// 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)"; 
 
    } 
 
}
/* 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; 
 
}
<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>