如何显示隐藏前一个的新模式窗口?

How to display a new modal window hiding the previous one?(如何显示隐藏前一个的新模式窗口?)
本文介绍了如何显示隐藏前一个的新模式窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 tympanus.net 模态(与伟大的动画)很容易删除背景 div(<div class="md-overlay"></div>)让我与我的模态后面的菜单项进行交互,但我没有知道如何一次只显示一个模态,因为当我打开一个新模态时,以前的模态仍然存在,而新模态出现在它上面.

Using tympanus.net modals (with greats animations) is easy to delete the backdrop div (<div class="md-overlay"></div>)letting me interact with menu items behind my modal but I don't know how to display just one modal at time as when I open a new one the previous still there and the new appear over it.

一切都由一个类 .md-show 控制,该类应用于被调用的模式.我认为我需要做的是删除所有应用的 .md-show 类,然后再用同一个类打开一个新类.也许有脚本?

Everything is controlled from a class .md-show which is applied to the called modal. I think what I need to do is delete all .md-show class applied before opening a new one with this same class. Maybe with a script?

更新:这是脚本:版权所有 2013,Codrops//对不起,我不能发表评论!它们不起作用!

UPDATE: This is the script: Copyright 2013, Codrops //sorry, I can't place comments! They doesn't works!

var ModalEffects = (function() {

    function init() {

        var overlay = document.querySelector( '.md-overlay' );

        [].slice.call( document.querySelectorAll( '.md-trigger' ) ).forEach( function( el, i ) {

            var modal = document.querySelector( '#' + el.getAttribute( 'data-modal' ) ),
                close = modal.querySelector( '.md-close' );

            function removeModal( hasPerspective ) {
                classie.remove( modal, 'md-show' );

                if( hasPerspective ) {
                    classie.remove( document.documentElement, 'md-perspective' );
                }
            }

            function removeModalHandler() {
                removeModal( classie.has( el, 'md-setperspective' ) ); 
            }

            el.addEventListener( 'click', function( ev ) {
                classie.add( modal, 'md-show' );
                overlay.removeEventListener( 'click', removeModalHandler );
                overlay.addEventListener( 'click', removeModalHandler );

                if( classie.has( el, 'md-setperspective' ) ) {
                    setTimeout( function() {
                        classie.add( document.documentElement, 'md-perspective' );
                    }, 25 );
                }
            });

            close.addEventListener( 'click', function( ev ) {
                ev.stopPropagation();
                removeModalHandler();
            });

        } );

    }

    init();

})();

我认为我需要在此处删除 .md-show,然后再打开新模式:

I Think I need to remove .md-show here, before opening the new modal:

 el.addEventListener( 'click', function( ev ) {
            classie.add( modal, 'md-show' );
            overlay.removeEventListener( 'click', removeModalHandler );
            overlay.addEventListener( 'click', removeModalHandler );

            if( classie.has( el, 'md-setperspective' ) ) {
                setTimeout( function() {
                    classie.add( document.documentElement, 'md-perspective' );
                }, 25 );
            }
        });

我做了一些尝试但没有任何成功,所以我们将不胜感激!:) 鼓膜参考文章

I made some tries without any success so some help will be appreciate! :) tympanus referring article

推荐答案

找到了一个使用 mousedown 和 mouseup 事件的有趣解决方案!

Found a funny solution using mousedown and mouseup events!

mousedown 将删除所有 md-show 类mouseup 将添加 md-show

mousedown will delete all md-show classes mouseup will add md-show

很简单,但是我在没有任何脚本知识的情况下花了 4 天时间才达到这个目标!

Easy but it took me 4 days to reach that without any knowledge on scripts!

完全正确的代码!

var ModalEffects = (function() {
    function init() {

    var overlay = document.querySelector( '.md-overlay' );

    [].slice.call( document.querySelectorAll( '.md-trigger' ) ).forEach( function( el, i ) {

        var modal = document.querySelector( '#' + el.getAttribute( 'data-modal' ) ),
            close = modal.querySelector( '.md-close' );

        function removeModal( hasPerspective ) {
            classie.remove( modal, 'md-show' );

            if( hasPerspective ) {
                classie.remove( document.documentElement, 'md-perspective' );
            }
        }

        function removeModalHandler() {
            removeModal( classie.has( el, 'md-setperspective' ) ); 
        }

        el.addEventListener( 'mouseup', function( ev ) {
            classie.add( modal, 'md-show' );
            overlay.removeEventListener( 'click', removeModalHandler );
            overlay.addEventListener( 'click', removeModalHandler );

            if( classie.has( el, 'md-setperspective' ) ) {
                setTimeout( function() {
                    classie.add( document.documentElement, 'md-perspective' );
                }, 25 );
            }
        });

        document.addEventListener( 'mousedown', function( ev ) {
            if (classie.has(ev.target, "md-close")) {
                ev.stopPropagation();
                removeModalHandler();
            }
        });

    } );

}

init();

})();

请注意,您需要在 md-trigger 链接中添加 md-close 类!

Please note that you need to add md-close class to md-trigger links!

这篇关于如何显示隐藏前一个的新模式窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)