網站首頁 編程語言 正文
本文實例為大家分享了JQuery自定義模態框效果的具體代碼,供大家參考,具體內容如下
重點:基于jQuery ,也可改造成原生模態框
功能:
1、可以自定義模態框的寬高等等一系列css樣式;
2、關閉、提交都可以執行自定義的回調函數;
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">批量關閉</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();
? ? ? ? })
? ? }
}
最后一步,調用:
$(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)
? ? })
})
原文鏈接:https://blog.csdn.net/u013492323/article/details/94553861
相關推薦
- 2022-12-08 oracle自動生成uuid的實現方法_oracle
- 2022-06-22 Android實現歡迎滑動頁面_Android
- 2023-06-19 阿里低代碼框架lowcode-engine設置默認容器詳解_React
- 2023-02-06 Python類中__init__()?和self的詳細解析_python
- 2022-10-22 Redis?布隆過濾器命令的使用詳解_Redis
- 2022-09-08 Docker容器使用方法詳解_docker
- 2022-09-26 設計模式類別,設計模式遵循的7個原則,工廠模式(靜態工廠,工廠方法,抽象工廠),7種單例模式
- 2023-01-19 python全局解釋器GIL鎖機制詳解_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支