init=()=>{
\t //SELECT & BIND (CLICK) EVENT
\t document.querySelector('login').addEventListener('click',modal.overlay.init);
}
modal={
\t overlay:{
\t \t init:()=>{
\t \t \t //CREATE OVERLAY
\t \t \t var overlay = document.createElement('overlay');
\t \t \t //SET (CLICK) EVENT TO REMOVE ITSLEF
\t \t \t overlay.addEventListener('click',modal.overlay.remove);
\t \t \t //APPEND TO INTERFACE
\t \t \t document.body.appendChild(overlay);
\t \t },
\t \t remove:(e)=>{
\t \t \t //REMOVE ITSELF
\t \t \t e.target.parentNode.removeChild(e.target);
\t \t } \t \t
\t }
}
//ON DOCUMENT LOAD RUN INIT
document.addEventListener('DOMContentLoaded',init);
html{
\t height: 100%;
\t width: 100%;
}
html *{
\t box-sizing: border-box;
\t -webkit-font-smoothing: antialiased;
\t
/* \t DISABLE USER SELECT */
\t -moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
body{
\t z-index: 100;
\t
\t margin: 0 !important;
\t
\t height: 100%;
\t width: 100%;
\t
\t display: flex;
\t flex-direction: column;
\t justify-content: center;
\t align-items: center; \t
\t
\t background: -webkit-radial-gradient(#41a3ff,#0273D4);
}
login{
position: relative;
margin: 1em 0 0 0;
padding: .25em 1.5em;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #0273D4;
border-width: 1px;
border-style: solid;
border-color: #0273D4;
text-transform: capitalize;
font-family: Roboto, sans-serif;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
login:hover{
color: white;
border-color: white;
/* background-color: rgba(255, 255, 255, 0.31); */
-webkit-box-shadow: 0px 2px 7px rgba(0, 0, 0, 0.40);
box-shadow: 0px 2px 7px rgba(0, 0, 0, 0.40);
}
login:active{
-webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) inset;
-moz-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) inset;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) inset;
}
overlay{
\t position: absolute;
\t top: 0;
\t left: 0;
\t display: flex;
height: 100vh;
width: 100vw;
justify-content: center;
flex-direction: column;
align-items: center;
background-color: rgba(0, 0, 0, 0.8);
}
<body>
\t <login>click me</login>
</body> \t
添加HTML,但我会为你提供反正一个例子。 –
欢迎来到StackOverflow,你的问题应该包含一个[最小,完整和可验证的例子](http://stackoverflow.com/help/mcve)。 – hungerstar