JQuery自定義模態(tài)框效果
本文實例為大家分享了JQuery自定義模態(tài)框效果的具體代碼,供大家參考,具體內(nèi)容如下
重點:基于jQuery ,也可改造成原生模態(tài)框
功能:
1、可以自定義模態(tài)框的寬高等等一系列css樣式;
2、關(guān)閉、提交都可以執(zhí)行自定義的回調(diào)函數(shù);
3、js和html分離,除了部分帶了js功能的class不能遺漏之外,其他的都可自行增減
html代碼:
<div class="dialog-tiya" id="voteModal"> ? ? <div class="modalBg-tiya"></div> ? ? <div class="customModal-tiya"> ? ? ? ? <div class="close"></div> ? ? ? ? <div class="modal-title"> ? ? ? ? ? ? 批量投票 ? ? ? ? </div> ? ? ? ? <div class="modal-body"> ? ? ? ? ? ? <p class="text-center color8bb7f9">是否批量開啟所選隊伍的投票?</p> ? ? ? ? </div> ? ? ? ? <div class="modal-footer"> ? ? ? ? ? ? <div class="button-refer">批量開啟</div> ? ? ? ? ? ? <div class="button-cancel">批量關(guān)閉</div> ? ? ? ? </div> ? ? </div> </div>
css代碼:
.dialog-tiya{
? ? display:none;
}
.modalBg-tiya {
? ? width: 100%;
? ? height: 100%;
? ? background: rgba(0, 0, 0, 0.3);
? ? position: fixed;
? ? z-index: 2;
? ? left: 0;
? ? top: 0;
}
.customModal-tiya {
? ? position: fixed;
? ? width: 40%;
? ? height: 50%;
? ? z-index: 3;
? ? left: 0;
? ? top: 0;
? ? bottom: 0;
? ? right: 0;
? ? margin: auto;
? ? border-radius: 5px;
? ? padding: 15px;
? ? box-sizing: border-box;
? ? background: #fff;
}
.customModal-tiya .modal-title {
? ? font-size: 18px;
? ? margin: 40px auto;
? ? color:#000;
? ? text-align:center;
}
.customModal-tiya .modal-footer {
? ? position: absolute;
? ? bottom: 15px;
? ? right: 15px;
? ? left: 15px;
? ? text-align: center;
}
.customModal-tiya .modal-footer .button-refer,
.customModal-tiya .modal-footer .button-cancel {
? ? width: 40%;
? ? height: 38px;
? ? line-height: 38px;
? ? text-align: center;
? ? border:1px solid #6893ff;
? ? font-size:16px;
? ? border-radius: 5px;
? ? display: inline-block;
}
.customModal-tiya .modal-footer .button-refer {
? ? margin-right: 10px;
? ? background: #6893ff;
? ? color:#fff;
}
.customModal-tiya .modal-footer .button-cancel {
? ? margin-left: 10px;
? ? color:#6893ff;
}
.customModal-tiya .close{
? ? position:absolute;
? ? right:15px;
? ? top:15px;
? ? width: 22px;
? ? height:22px;
? ? background:#8bb7f9 url("../public/images/gb_icon.png") no-repeat;/*自己換icon*/
? ? background-size:100% 100%;
? ? cursor:pointer;
}
.customModal-tiya .modal-body{
? ? font-size:18px;
}
.text-center{
? ? text-align:center;
}
.color8bb7f9{
? ? color:#8bb7f9;
}modal.js:
function CustomModal(ele,options,callback){
? ? this.ele = ele;
? ? this.init(ele,options,callback);
}
customModal.prototype.init = function(ele,options,callback){
? ? ele.show();
? ? if(options.style){
? ? ? ? var target = ele.find(".customModal-tiya");
? ? ? ? $.each(options.style,function(index,item){
? ? ? ? ? ? target.css(index,item)
? ? ? ? })
? ? }
? ? callback && callback();
? ? if(options.close){
? ? ? ? ele.find(".close").click(function(){
? ? ? ? ? ? ele.hide();
? ? ? ? ? ? options.close && options.close();
? ? ? ? })
? ? }
? ? if(options.submit){
? ? ? ? ele.find(".button-refer").click(function(){
? ? ? ? ? ? ele.hide();
? ? ? ? ? ? options.submit && options.submit();
? ? ? ? })
? ? }
? ? if(options.cancel) {
? ? ? ? ele.find(".button-cancel").click(function(){
? ? ? ? ? ? ele.hide();
? ? ? ? ? ? options.cancel && options.cancel();
? ? ? ? })
? ? }
}最后一步,調(diào)用:
$(function(){
? ? var voteModal = new CustomModal($("#voteModal"),{
? ? ? ? style:{
? ? ? ? ? ? 'min-height':'300px',
? ? ? ? ? ? 'min-width':'600px',
? ? ? ? },
? ? ? ? close:function(){
? ? ? ? ? alert(2)
? ? ? ? },
? ? ? ? submit:function(){
? ? ? ? ? ? alert(3)
? ? ? ? },
? ? ? ? cancel:function(){
? ? ? ? ? ? alert(4)
? ? ? ? }},function(){
? ? ? ? alert(1)
? ? })
})以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery Selectors(選擇器)的使用(四-五、內(nèi)容篇&可見性篇)
本系列文章主要講述jQuery框架的選擇器(Selectors)使用方法,我將以實例方式進行講述,以簡單,全面為基礎(chǔ),不會涉及很深,我的學(xué)習(xí)方法:先入門,后進階!2009-12-12
jQuery中的Deferred和promise 的區(qū)別
這篇文章主要介紹了jQuery中的Deferred和promise 的區(qū)別的相關(guān)資料,需要的朋友可以參考下2016-04-04
jQuery監(jiān)控文本框事件并作相應(yīng)處理的方法
這篇文章主要介紹了jQuery監(jiān)控文本框事件并作相應(yīng)處理的方法,涉及jQuery操作文本框的技巧,需要的朋友可以參考下2015-04-04
jQuery Real Person驗證碼插件防止表單自動提交
這篇文章為大家介紹了一款jQuery驗證碼插件Real Person,可以防止自動提交表單2015-11-11
jQuery Layer彈出層傳值到父頁面的實現(xiàn)代碼
這篇文章主要介紹了jQuery Layer彈出層傳值到父頁面的實現(xiàn)代碼,需要的朋友可以參考下2017-08-08

