jquery實(shí)現(xiàn)簡(jiǎn)單的彈窗效果
本文實(shí)例為大家分享了jquery實(shí)現(xiàn)簡(jiǎn)單彈窗效果的具體代碼,供大家參考,具體內(nèi)容如下
效果實(shí)現(xiàn)圖
css代碼
h1,p,h2{ margin: 0; padding: 0; } .modal_info{ display: flex; visibility: hidden; flex-direction: column; align-items: flex-start; justify-content: flex-start; width: 200px; height: auto; position: fixed; margin:auto; background-color: #FFFFFF; border-radius: 3px; top: 45%; left: 50%; box-sizing: border-box; z-index: 111; -webkit-transform: scale(0.7); -moz-transform: scale(0.7); -ms-transform: scale(0.7); transform: scale(0.7); opacity: 0; -webkit-transition: all 0.3s; -moz-transition: all 0.3s; transition: all 0.3s; } .modal_info .head_blue{ padding: 5px 10px; height: auto; box-sizing: border-box; background: #2262C6; font-style: normal; font-weight: bold; font-size: 18px; line-height: 18px; color: #FFFFFF; width: 100%; display: flex; flex-direction: row; align-items: center; justify-content: space-between !important; text-transform:capitalize; } .modal_info .head_blue h1{ font-size: 18px; color: white; } .modal_info .body_main{ display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 10px 10px; background-color: #FFFFFF; flex: 1; width: 100%; box-sizing: border-box; } .modal_info .bottom_button{ display: flex; flex-direction: row; align-items: center; justify-content: space-around; width: 100%; padding: 10px; box-sizing: border-box; } .modal_info .bottom_button div{ display: flex; flex-direction: row; align-items: center; justify-content: center; padding: 5px; box-sizing: border-box; } .modal_info .bottom_button .yes{ background-color: #2262C6; color: #FFFFFF; } .modal_info .bottom_button .no{ background-color: #FFFFFF; color: #505050; border: 1px solid #505050; } .md-show{ visibility:visible !important; -webkit-transform: scale(1); -moz-transform: scale(1); -ms-transform: scale(1); transform: scale(1); opacity: 1; }
html代碼加上jquery代碼,注意里面的引用的css和js
jquery可以下載任意一個(gè)版本放入
<!DOCTYPE html> <html> <head> <title>彈窗</title> <link rel="stylesheet" href="./modal.css" /> </head> <body style="background-color: black;"> <div class="button_click" style="background-color:#FFFFFF;width: 100px;height: 100px;">點(diǎn)擊這個(gè)</div> </body> <script type="text/javascript" src="jquery-3.5.1.min.js"></script> <script> function modal_confirm(option){ var {title,question,content,confirm,cancel,style,btn} = option; var yes_confirm,no_cancel; btn.forEach(item=>{ if(item.yes){ yes_confirm = item.yes; } else if(item.cancel){ no_cancel = item.cancel; } } ) if($('.modal_info')){ $('.modal_info').remove(); } $('body').append(`<div class="modal_info" style="${style?style:''}"></div>`); var modal = $('.modal_info'); modal.append(`<div class="head_blue"><h1>${title?title:'title'}</h1></div>`); modal.append(`<div class="body_main"><h1>${question?question:'question'}</h1><p>${content?content:'content'}</p></div>`); modal.append(`<div class="bottom_button"><div class="yes">${confirm?confirm:'confirm'}</div><div class="no">${cancel?cancel:'cancel'}</div></div>`); setTimeout(() => { $('.modal_info').addClass('md-show'); }, 10); $('.yes,.no').on('click',function(){ if($(this).attr('class')==='yes') { yes_confirm(); } else{ no_cancel(); } $('.modal_info').removeClass('md-show'); setTimeout(()=>{ this.parentNode.parentNode.remove(); },300); }) } $('.button_click').on('click',function(){ modal_confirm({ title:'標(biāo)題', question:'', content:'content', confirm:'', cancel:'cancel', style: 'width:200px;height:200px', btn:[{ yes:function(){ console.log('這個(gè)是confirm'); } }, { cancel:function(){ console.log('這個(gè)是cancel'); } } ] }); }) </script> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery實(shí)現(xiàn)的兩種簡(jiǎn)單彈窗效果示例
- jquery實(shí)現(xiàn)彈窗(系統(tǒng)提示框)效果
- Jquery實(shí)現(xiàn)自定義彈窗示例
- jquery ui dialog實(shí)現(xiàn)彈窗特效的思路及代碼
- 小巧強(qiáng)大的jquery layer彈窗彈層插件
- 簡(jiǎn)單實(shí)現(xiàn)jQuery彈窗效果
- jQuery實(shí)現(xiàn)彈窗居中效果類似alert()
- jquery實(shí)現(xiàn)彈窗功能(窗口居中顯示)
- jquery制作彈窗提示窗口代碼分享
- 運(yùn)用JQuery的toggle實(shí)現(xiàn)網(wǎng)頁(yè)加載完成自動(dòng)彈窗
相關(guān)文章
jQuery手動(dòng)點(diǎn)擊實(shí)現(xiàn)圖片輪播特效
這篇文章主要為大家詳細(xì)介紹了jQuery手動(dòng)點(diǎn)擊實(shí)現(xiàn)圖片輪播特效,手動(dòng)點(diǎn)擊數(shù)字卡片實(shí)現(xiàn)圖片輪播,對(duì)圖片輪播感興趣的小伙伴們可以參考一下2015-12-12使用jquery自定義鼠標(biāo)樣式滿足個(gè)性需求
瀏覽器是有自帶的鼠標(biāo)樣式的,如果某些時(shí)候?yàn)榱吮3质髽?biāo)樣式的統(tǒng)一,或者想指定特定的鼠標(biāo)樣式該怎么辦呢?那就要使用自定義了,下面有個(gè)不錯(cuò)的示例,喜歡的朋友可以參考下2013-11-11JQuery實(shí)現(xiàn)列表中復(fù)選框全選反選功能封裝(推薦)
在做列表時(shí)經(jīng)常會(huì)遇到全選,反選進(jìn)行批量處理問題。通過本文給大家介紹JQuery實(shí)現(xiàn)列表中復(fù)選框全選反選功能封裝,對(duì)jq復(fù)選框全選反選功能感興趣的朋友一起看看吧2016-11-11jQuery中關(guān)于ScrollableGridPlugin.js(固定表頭)插件的使用逐步解析
以前寫前臺(tái)的時(shí)候需要用哪些效果從來都是有現(xiàn)成的東西拿來就用的,因?yàn)樽约赫娴氖怯行校翢o探索精神,只重視結(jié)果,不追求過程2014-07-07一些主流JS框架中DOMReady事件的實(shí)現(xiàn)小結(jié)
在實(shí)際應(yīng)用中,我們經(jīng)常會(huì)遇到這樣的場(chǎng)景,當(dāng)頁(yè)面加載完成后去做一些事情:綁定事件、DOM操作某些結(jié)點(diǎn)等。2011-02-02在JQuery dialog里的服務(wù)器控件 事件失效問題
今天遇到個(gè)問題,在dialog中放了服務(wù)器端的空間dropdownlist,但是寫selectindexchange事件卻怎么也觸發(fā)不了,然后就在網(wǎng)上搜,終于看到有個(gè)哥們解決了這個(gè)問題,真的謝謝他。2010-12-12jquery與google map api結(jié)合使用 控件,監(jiān)聽器
關(guān)于jquery的獲取不再此處累贅,網(wǎng)上有許多關(guān)于jquery的介紹。2010-03-03jQuery slider Content(左右控制移動(dòng))
jQuery slider Content(左右控制移動(dòng))實(shí)現(xiàn)代碼,大家可以參考下。2009-09-09