jquery支持多层嵌套的弹出层对话框特效代码

所属分类: 网页特效-弹出层    2024-01-10 10:12:07

jquery支持多层嵌套的弹出层对话框特效代码 ie兼容6
反馈问题  查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery支持多层嵌套的弹出层对话框特效代码(共3个文件)

    • index.html

使用方法

(function ($) {
	
    var Modally = function(id, elem, params) {
        var self = this;
        this.id = id;
        this.$element = $(elem);
        this.params = params;
        this.initial_z_index = null;

        if (this.params === undefined || this.params === null) {
            this.params = {};
        }

        this.$template = $('<div class="modally-wrap"><div class="modally-table"><div class="modally-cell"><div class="modally-underlay modally-close"></div><div class="modally"><div class="modally-close modally-close-button">×</div><div class="modally-content"></div></div></div></div></div>');

        var defaults = {
            'max_width': 'none',
            'vertical_align': 'middle',
            'close_parent': false,
            'close_other': false,
        };

        // TODO: events pre open, post open, pre close, post close

        // TODO: animation open
        // TODO: animation close
        // TODO: responsive

        function __init__() {
            for (var k in defaults) {
                //load in defaults
    			if (!self.params.hasOwnProperty(k)) {
    				self.params[k] = defaults[k];
    			}

                //check for inline properties
                var attr = self.$element.attr('modally-'+k)

                if (attr) {
                    if (k === 'max_width' && attr !== 'none') {
                        attr = parseInt(attr, 10);
                    }

                    if (k === 'close_parent' && attr === 'false') {
                        attr = false;
                    }

                    self.params[k] = attr;
                }
    		}

            //setup
            self.$template.find('.modally').css({
                'max-width': self.params.max_width
            });

            self.$template.find('.modally-cell').css({
                'vertical-align': self.params.vertical_align
            });

            self.$element.data('modally', self);
            self.$template.data('modally', self);

            var ghost = self.$element.detach();
            self.$template.find('.modally-content').append(ghost);
            self.$template.addClass(self.id);
            self.$template.find('.modally-close').on('click', function(){
                self.close();
            });
            $('body').append(self.$template);

            if (self.initial_z_index === null) {
                self.initial_z_index = self.$template.css('z-index');
            }
        }
        __init__();
    };

    Modally.prototype.open = function(e, callback) {
        var $parent_modally = $(e.target).closest('.modally-wrap');
        $('body').addClass('modally-open modally-'+this.id);

        $('.modally-wrap.open').removeClass('last');
        this.$template.addClass('open last');

        if ($parent_modally.length) {
            var data = $parent_modally.data('modally');

            if (this.params.close_parent) {
                var self = this;
                data.close(e, function() {
                    self.$template.fadeIn();
                });

                if (callback) {
                    callback(this, e);
                }
                return this;
            } else {
                this.temp_parent = data;
            }
            // TODO: return to previously closed modal (there is a smart way to do it)

            this.$template.css('z-index', data.initial_z_index + 1);
        }

        this.$template.fadeIn();

        if (callback) {
            callback(this, e);
        }

        return this;
    };

    Modally.prototype.close = function(e, callback) {
        this.$template.fadeOut();
        this.$template.removeClass('open');

        if (this.$template.hasClass('last') && this.temp_parent) {
            this.temp_parent.$template.addClass('last');
            this.$template.removeClass('last');
            delete this.temp_parent;
        }

        if (!$('.modally-wrap.open').length) {
            $('.modally-wrap').removeClass('last');
            $('body').removeClass('modally-open');
        }

        if (this.params.close_parent) {
            if (callback) {
                callback(this, e);
            }

            $('body').removeClass('modally-'+this.id);

            return this;
        }

        if (this.initial_z_index !== this.$template.css('z-index')) {
            this.$template.css('z-index', this.initial_z_index);
        }

        if (callback) {
            callback(this, e);
        }

        $('body').removeClass('modally-'+this.id);

        return this;
    };

    $.fn.modally = function(id, params) {

        if (!window.hasOwnProperty('_modally_storage')) {
            window._modally_storage = {};
        }

		var $this = $(this);

        if (id === undefined || id === null) {
            id = $this.attr('id');
        }

        if (id === undefined || id === null || id === '') {
            console.error('jquery.modally >> in order to use this plugin you need to provide a unique ID for each modal manually or automatically throughout target element\'s ID attribute.');
            return $this;
        }

        if (!window._modally_storage.hasOwnProperty(id)) {
            window._modally_storage[id] = new Modally(id, $this, params);
        } else {
            console.warn('jquery.modally >> modal with the provided ID: "' + id +'" already exists. Rewriting.');
        }

		return $this;
    };

    function _modallyTrigger(e, elem, action) {
        var href = $(elem).attr('href');

        if (href === undefined
            || href === null
            || href === ''
            || href === '#') {
            if (action === 'close') {
                var $parent = $(e.target).closest('.modally-wrap');
                if ($parent.length) {
                    var data = $parent.data('modally');
                    data.close();
                    return;
                }
            }

            console.error('jquery.modally >> href attribute needs to contain the existing modal ID');
            return;
        }

        if (/^#/ig.test(href) && href.length > 1) {
            href = href.replace('#', '');
        }

        if (window.hasOwnProperty('_modally_storage') && window._modally_storage.hasOwnProperty(href)) {
            window._modally_storage[href][action](e);
        } else {
            console.error('jquery.modally >> no modal by provided ID: ' + href);
        }
    }

    function _modallyTriggerOpen(e) {
        e.preventDefault();
        _modallyTrigger(e, this, 'open');
    }

    function _modallyTriggerClose(e) {
        e.preventDefault();
        _modallyTrigger(e, this, 'close');
    }

    $(document).on('click', 'a[target="_modal"]', _modallyTriggerOpen);
    $(document).on('click', 'a[target="_modal:open"]', _modallyTriggerOpen);
    $(document).on('click', 'a[target="_modal:close"]', _modallyTriggerClose);
})(jQuery);

站长提示:
1. 平台上所有素材资源,需注册登录会员方能正常下载。
2. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励20K币
3. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
4. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 弹出层

jquery轻量级鼠标悬停文字工具提示插件

一款可自定义的文本文字工具提示插件,鼠标悬停于元素上触发文字提示特效,可引导用户对某个功能模块的说明。
  弹出层
 193  

jquery支持iframe内嵌网页的自定义弹出层插件

vibox是一个响应式自定义弹出层插件,支持iframe内嵌网页(例如:指定页面或视频等)嵌入到可自定义的模式弹出窗口中。
  弹出层
 213  

Toaster响应式网页右上角弹出消息插件

一款浏览器右上角弹出提示消息特效代码,可自定义设置自动关闭。
  弹出层
 113  

jquery响应式简单的自定义弹出窗口插件

一款简单易用的自定义弹出层,可直接使用DIV定义弹出窗口内容,点击按钮显示弹出层。
  弹出层
 144  

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论