gpt4 book ai didi

javascript - 关闭全屏菜单覆盖

转载 作者:行者123 更新时间:2023-11-29 16:03:12 26 4
gpt4 key购买 nike

我的全屏菜单覆盖有一个关闭按钮,但我也想通过单击覆盖本身来关闭覆盖。因此,如果您在覆盖层上的菜单外部单击,覆盖层将关闭。与 close btw 相同。她是代码,但要添加或编辑什么。

(function() {
var triggerBttn = document.getElementById( 'trigger-overlay' ),
overlay = document.querySelector( 'div.overlay' ),
closeBttn = overlay.querySelector( 'button.overlay-close' );
transEndEventNames = {
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'transitionend',
'OTransition': 'oTransitionEnd',
'msTransition': 'MSTransitionEnd',
'transition': 'transitionend'
},
transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
support = { transitions : Modernizr.csstransitions };

function toggleOverlay() {
if( classie.has( overlay, 'open' ) ) {
classie.remove( overlay, 'open' );
classie.add( overlay, 'close' );
var onEndTransitionFn = function( ev ) {
if( support.transitions ) {
if( ev.propertyName !== 'visibility' ) return;
this.removeEventListener( transEndEventName, onEndTransitionFn );
}
classie.remove( overlay, 'close' );
};
if( support.transitions ) {
overlay.addEventListener( transEndEventName, onEndTransitionFn );
}
else {
onEndTransitionFn();
}
}
else if( !classie.has( overlay, 'close' ) ) {
classie.add( overlay, 'open' );
}
}

triggerBttn.addEventListener( 'click', toggleOverlay );
closeBttn.addEventListener( 'click', toggleOverlay );
})();

最佳答案

您需要做的就是在整个覆盖 div 上放置一个“点击”事件监听器。

overlay.addEventListener( 'click', toggleOverlay );

在底部

关于javascript - 关闭全屏菜单覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37470912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com