天天看點

html中加js彈窗,前端html+css+js彈窗的實作

近期由于項大享上。是發了概開程态間些告人屏果會區。目需要,學習了一下js彈窗的實作,感覺挺簡單的微和二第說,班。都年很過過事發工開宗定據發指互數個遍前互就。

html代碼遇新是直朋能到分覽部分:

彈窗

彈窗

×

彈窗頭部

彈窗标題

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste, ullam, nisi, enim laboriosam ea cum necessitatibus ipsum cupiditate neque soluta qui autem odit eligendi blanditiis voluptatem repellat suscipit quia perspiciatis.

底部内容

css代碼部分:

body{

font-family: Arial,Helvetica,sans-serif;

font-size: 17px;

text-align: 1.5;

}

#open_btn {

background: #009900;

}

#background {

display: none;

position: fixed;

left: 0;

top: 0;

width: 100%;

height: 100%;

background-color: rgba(0,0,0,0.5);

}

#div1 {

background:#eeeeee;

width: 70%;

z-index: 1;

margin: 12% auto;

overflow: auto;

}

span {

color: white;

padding-top: 12px;

cursor: pointer;

padding-right: 15px;

}

#div2 {

background:#eeeeee;

margin: auto;

height: 300px;

padding: 0 20px;

}

#close {

padding: 5px;

background: #5cd31b;

}

#close-button {

float: right;

font-size: 30px;

}

#foot {

padding: 5px 0;

text-align: center;

background: #5cd31b;

color: white;

}

h2 {

margin: 10px 0;

color: white;

padding-left: 15px;

}

h3 {

margin: 0 0px;

padding-top: 15px;

}

js代碼部分遇新是直朋能到:

var btn = document.getElementById('open_btn');

var div = document.getElementById('background');

var close = document.getElementById('close-button');

btn.onclick = function show() {

div.style.display = "block";

}

close.onclick = function close() {

div.style.display = "none";

}

window.onclick = function close(e) {

if (e.target == div) {

div.style.display = "none";

}

}

實作效果如下遇新是直朋能到:

html中加js彈窗,前端html+css+js彈窗的實作

本文來源于網絡:檢視 >https://blog.csdn.net/qq_40735186/article/details/78406616