原生js實(shí)現(xiàn)簡(jiǎn)單的模態(tài)框示例
html部分:
<img src="images/8.jpg" alt=""> <button class="btn" id="showMax">顯示大圖</button> <div id="modalBox" class="modalBox"> <div class="modalBox-matter"> <header class="modalBox-header"> <span class="mtclose">×</span> </header> <div class="modalBox-body"> <img src="images/8-1.jpg"> </div> </div> </div>
js部分:
var btn = document.getElementById('showMax');
var mtclose = document.getElementsByClassName('mtclose')[0];
var modalBox = document.getElementById('modalBox');
btn.addEventListener('click', function(){
modalBox.style.display = "block";
});
mtclose.addEventListener('click', function(){
modalBox.style.display = "none";
});
css部分:
.btn{
width: 100px;
height: 35px;
border-radius: 5px;
font-size: 16px;
color: #F97B39;
position: absolute;
top: 130px;
left: 160px;
opacity: 0.2;
cursor: pointer; /*鼠標(biāo)小手*/
}
.btn:hover, .btn:focus{ /*focus 取得焦點(diǎn)狀態(tài)*/
background-color: #8AA7F9;
opacity: 0.5;
color: #FFFFFF;
}
.modalBox{
display: none;
width: 100%;
height: 100%;
position: fixed;
left: 0;
top: 0;
z-index: 1000;
background-color: rgba(0,0,0,0.5);
}
.modalBox-matter{
display: flex; /*/*彈性布局*/
flex-flow: column nowrap;
justify-content: space-between; /*兩端對(duì)齊*/
width: 50%;
height: 80%;
margin: 30px auto 100px;
border-radius:10px;
-webkit-animation: zoom 0.6s;
animation: zoom 0.6s;
resize: both;
overflow: auto;
}
@keyframes zoom{
from {transform: scale(0)}
to {transform: scale(1)}
}
.modalBox-header{
margin-left: 617px;
}
.mtclose{
color: #602E2A;
font-size: 3em;
font-weight: bold;
transition: all 0.3s;
/*z-index: 1010; */
}
.mtclose:hover, .mtclose:focus{
color: #602E2A;
cursor: pointer;
}
.modalBox-body{
padding: 10px;
font-size: 16px;
}
效果


因?yàn)檎谶M(jìn)行的一個(gè)項(xiàng)目中,需要一個(gè)模態(tài)框,所以花時(shí)間在網(wǎng)上自學(xué)的,相對(duì)來說比較簡(jiǎn)單,可以自行修改內(nèi)容。。。
以上這篇原生js實(shí)現(xiàn)簡(jiǎn)單的模態(tài)框示例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- AngularJs 彈出模態(tài)框(model)
- JS實(shí)現(xiàn)圖片點(diǎn)擊后出現(xiàn)模態(tài)框效果
- js實(shí)現(xiàn)簡(jiǎn)單模態(tài)框?qū)嵗?/a>
- Vue.js彈出模態(tài)框組件開發(fā)的示例代碼
- js利用事件的阻止冒泡實(shí)現(xiàn)點(diǎn)擊空白模態(tài)框的隱藏
- angularJS模態(tài)框$modal實(shí)例代碼
- AngularJS中使用ngModal模態(tài)框?qū)嵗?/a>
- bootstrap Validator 模態(tài)框、jsp、表單驗(yàn)證 Ajax提交功能
- AngularJS模態(tài)框模板ngDialog的使用詳解
- JavaScript+CSS實(shí)現(xiàn)模態(tài)框效果
相關(guān)文章
js獲取html頁面代碼中圖片地址的實(shí)現(xiàn)代碼
這篇文章主要介紹了js獲取html代碼中圖片地址的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-03-03
JS實(shí)現(xiàn)兼容火狐及IE iframe onload屬性的遮罩層隱藏及顯示效果
這篇文章主要介紹了JS實(shí)現(xiàn)兼容火狐及IE iframe onload屬性的遮罩層隱藏及顯示效果,涉及javascript事件響應(yīng)及針對(duì)頁面元素屬性的動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-08-08
Javascript使用post方法提交數(shù)據(jù)實(shí)例
這篇文章主要介紹了Javascript使用post方法提交數(shù)據(jù),實(shí)例分析了javascript實(shí)現(xiàn)post提交數(shù)據(jù)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
ElementUI的Dialog彈窗實(shí)現(xiàn)拖拽移動(dòng)功能示例代碼
這篇文章主要介紹了ElementUI的Dialog彈窗實(shí)現(xiàn)拖拽移動(dòng)功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07
JavaScript 節(jié)點(diǎn)操作 以及DOMDocument屬性和方法
最近發(fā)現(xiàn)DOMDocument對(duì)象很重要,還有XMLHTTP也很重要 注意大小寫一定不能弄錯(cuò).2007-12-12
javascript代碼在ie8里報(bào)錯(cuò) document.getElementById(...) 為空或不是對(duì)象的解決方
今天更升級(jí)了ie8,發(fā)現(xiàn)原來在ie7下可以運(yùn)行的代碼,不能運(yùn)行了,發(fā)現(xiàn)了一些細(xì)節(jié),附臨時(shí)修改辦法。2009-11-11

