Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
<!DOCTYPE html>
<html>
<head>
<title>open modal dialog and place overlay over rest of website</title>
<meta charset="UTF-8">
<style>
* {
font-family: Trebuchet MS, sans-serif;
color: #6489C9;
}
#overlay {
z-index: 10000;
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
}
#dialog {
z-index: 10001;
position: fixed;
left: 50%;
top: 50%;
padding: 20px;
border: 5px solid #6489C9;
border-radius: 10px;
background-color: #FFFFFF;
text-align: center;
overflow: auto;
width: 60%;
height: 50%;
transform: translate(-50%, -50%);
}
</style>
<!-- hack for IE: IE ≤ 9 does not support transfrom and IE ≤ 8 does not support alpha-transparency with rgba() and opacity -->
<!--[if lte IE 9]>
<style>
#overlay {
background-color: #000000;
opacity: 0.5;
filter:alpha(opacity=50);
}
#dialog {
width: 500px;
margin-left: -250px; /* negative half of width */
height: 300px;
margin-top: -150px; /* negative half of height */
}
</style>
<![endif]-->
<script>
function bindEvent(el, evt, fct){
if(document.addEventListener){
el.addEventListener(evt, fct);
}
else{
if(evt === "DOMContentLoaded"){
el = window;
evt = "load";
}
evt = "on" + evt;
if(document.attachEvent){
el.attachEvent(evt, fct);
}
else{
el.evt = fct;
}
}
console.log("added Eventlistener „" + evt + "“ to element ", el, ".\nBound function: ", fct);
}
function overlay(dialog){
var overlay = document.createElement("div");
overlay.id = "overlay";
bindEvent(overlay, "click", function(){
dialog.style.display = "none";
document.body.removeChild(overlay);
});
document.body.appendChild(overlay);
dialog.style.display = "";
}
bindEvent(document, "DOMContentLoaded", function(){
document.getElementById("call").onclick = function(){
overlay(document.getElementById("dialog"));
}
});
</script>
</head>
<body>
<div id="dialog" style="display:none">
<h1>login:</h1><br>
username: <input type="text"> password: <input type="password"><br><br>
<button> login </button>
</div>
<h1>open modal dialog and place overlay over rest of website</h1>
<br>
<button id="call"> open dialog </button>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<p>footer</p>
</body>
</html>
Ja, denke ich auch, da ja nicht nur JS gefragt ist. Daher verschoben.@Mods: diese Frage gehört m.E. eher nach CSS/HTML oder Allgemeines.
Bitteschön - gern geschehen. Du kannst dir das Ganze ja mal in Ruhe ansehen, und wenn sich dann Fragen ergeben sollten, die einfach hier stellen.Danke für die Antworten und das Beispiel.