JQuery自定义模态框效果

本文实例为大家分享了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)
    })
})

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • jQuery将多条数据插入模态框的示例代码

    //Bootstrap模态框(局部) <div class="modal fade" id="orderDetail"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> </div> <div class="modal

  • jQuery UI Grid 模态框中的表格实例代码

    在弹出的模态框中使用表格. 在某些情况下,特别是 bootstrap modal,可能会出现表格渲染宽度过小或有时显示不完全.会误认为是由于 bootstrap modal 的动画渲染导致表格渲染时的可用空间不如预期.可以通过调用handleWindowResize来纠正.动画渲染的时间不好确定,所以一般推荐使用$interval,在模态框打开后的5秒内每隔500ms循环调用. 从某种意义上说,这类似于自动调整大小的功能,但它只在模态框开启后的短时间内完成. 代码: index.html <!d

  • jQuery点击弹出层弹出模态框点击模态框消失代码分享

    废话不多说了,直接给大家贴代码了,具体代码如下所示: <!DOCTYPE html> <html> <head> <title>jQuery弹出层 模态框</title> <script src="./jquery.min.js" type="text/javascript"></script> <style> .btn{ height:100px; } .black_o

  • 使用jQuery将多条数据插入模态框的实现代码

    复制代码 代码如下: //Bootstrap模态框(局部) <div class="modal fade" id="orderDetail"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> </div> <div class=

  • jQuery实现淡入淡出的模态框

    本文实例为大家总结了jQuery淡入淡出模态框的使用方法,供大家参考,具体内容如下 HTML代码如下:固定格式就省略了 <div class="theme-popover"> <div class="theme-poptit"> <a href="#" rel="external nofollow" class="close">×</a> <h3>

  • JQuery自定义模态框效果

    本文实例为大家分享了JQuery自定义模态框效果的具体代码,供大家参考,具体内容如下 重点:基于jQuery ,也可改造成原生模态框 功能: 1.可以自定义模态框的宽高等等一系列css样式:2.关闭.提交都可以执行自定义的回调函数:3.js和html分离,除了部分带了js功能的class不能遗漏之外,其他的都可自行增减 html代码: <div class="dialog-tiya" id="voteModal">     <div class=&

  • 使用bootstrap插件实现模态框效果

    今天我们选择使用著名的 bootstrap 库的模态框插件 modal.js 来实现模态框效果,同时也使大家进一步熟悉 bootstrap 的插件使用. 一. bootstrap 的 js 插件的简单介绍 1.引入 我们在使用 bootstrap 库时,引入的文件 bootstrap.js 或者 bootstrap.min.js 就是 bootstrap的插件文件,这两种文件都集成了 bootstrap 的所有插件,区别在于 *.min.js 是压缩后的版本. 我们在使用 bootstrap 的

  • 详解钉钉小程序组件之自定义模态框(弹窗封装实现)

    背景 开发钉钉小程序中需要用到模态框 文档里也没有 自己搞一个- 效果大概长这个样 点击指定按钮,弹出模态框,里面的内容可以自定义,可以是简单的文字提示,也可以输入框等复杂布局.操作完点击取消或确定关闭. 开始封装 上图所示文件内容放入项目即可 (路径自己高兴着来) modal.js 内容不多 但都是精华 /** * 自定义modal浮层 * 使用方法: * <modal show="{{showModal}}" height='80%' onCancel="modal

  • 微信小程序自定义模态框

    本文实例为大家分享了微信小程序自定义模态框的具体代码,供大家参考,具体内容如下 效果展示 可在模态框中添加图片输入框 代码展示-wxml <button class="show-btn" bindtap="showDialogBtn">弹窗</button>     <view       class="modal-mask"       bindtap="hideModal"       cat

  • ionic 自定义弹框效果

    在工作过程中往往需要自定义的弹框.因此,将内容整理如下,以方便学习.若有不当之处,敬请斧正! 思路 利用ionic自带的弹框$ionicPopup. 隐藏头部和尾部,只保留body部分 在利用templateUrl或者template,引入需要的模板 代码 $ionicPopup.show({ cssClass:'team-popup', template: "<div class='list popup-form'>" + "<div class = 'f

  • JS实现图片点击后出现模态框效果

    很多时候我们在浏览图片时,会发现点击图片后,会弹出一个被点击图片的放大图片浮在页面上,占满整个窗口.这就是图片模态框效果. 这个效果可以使用某些js库实现,如bpopupJs.但是在这里我们使用纯js实现,能够更好理解效果原理和实现方法. 一.实现思路 我们点击小图片之后,图片模态框出现,同时图片模态框上有一个关闭按钮和图片的标题. 因此,我们的实现思路就是: 图片模态框有大图片,关闭按钮,图片标题三部分. 将图片模态框隐藏,在点击小图片之后,模态框出现. 点击关闭按钮后,模态框隐藏. 二.HT

  • jQuery实现穿梭框效果

    本文实例为大家分享了jQuery实现穿梭框效果的具体代码,供大家参考,具体内容如下 简介:今天给大家带来穿梭框的实现 布局的实现 <div id="box"> <div id="boxleft"> <ul id="left_ul"> </ul> </div> <div id="boxbtn"> <button id="btn_right&q

  • vue自定义弹框效果(确认框、提示框)

    本文实例为大家分享了vue自定义弹框效果的具体代码,供大家参考,具体内容如下 1.自定义确认框和提示框 根据传入的type来判断是确认框或提示框 <template> <transition name="confirm-fade"> <div v-if="isShowConfirm" class="my-confirm" @click.stop="clickFun('clickCancel')"&

  • 小程序自定义弹框效果

    本文实例为大家分享了小程序自定义弹框效果的具体代码,供大家参考,具体内容如下 wxml <!--button--> <view class="btn" bindtap="powerDrawer" data-statu="open">来点我呀</view> <!--mask--> <view class="drawer_screen" bindtap="powerD

  • Flutter自定义搜索框效果

    本文实例为大家分享了Flutter自定义搜索框效果的具体代码,供大家参考,具体内容如下 效果 实现方式 import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:keduo/base/baseSize.dart'; import 'package:keduo/utils/icon_utils.dart'; class SearchBarWidget extends Stateful

随机推荐