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


- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06