How to display a new modal window hiding the previous one?

前端 未结 1 1553
不知归路
不知归路 2021-01-26 15:59

Using tympanus.net modals (with greats animations) is easy to delete the backdrop div (

)letting me interact with menu it
相关标签:
1条回答
  • 2021-01-26 16:13

    Found a funny solution using mousedown and mouseup events!

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

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

    FULL RIGHT CODE!

    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();
    

    })();

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

    0 讨论(0)
提交回复
热议问题