gpt4 book ai didi

javascript - 如何使用纯 javascript 显示和隐藏模态对话框?

转载 作者:太空宇宙 更新时间:2023-11-04 13:28:15 25 4
gpt4 key购买 nike

我有一个对话框,我想使用纯 javascript 显示/隐藏它。我使用了 modal.classList.add('hide');它隐藏了它,但随后整个屏幕卡住,我无法点击任何东西。隐藏和显示动画对于我正在构建的对话框来说是最重要的,这就是我采用这种方法的原因。这是我的模态对话框

 <div class="modal fade">
<div class="modal-dialog">
<div class="modal-content" >
<div class="modal-header">
<a class="close button">

<paper-button raied type="button" class="close" id="close" aria-hidden="true" on-click="close">Close</paper-button>
</a>
<h2 class="modal-title">Title</h2>
</div>
<div class="modal-body next">
<img class='modal-img' />
</div>
<div class="modal-footer">
<paper-button raied id="previous" type="button" class="pull-left prev" on-click="prev">Previous</paper-button>
<paper-button raied id="next" type="button" class="next" on-click="next">Next</paper-button>
</div>
</div>
</div>
</div>

这里是关闭对话框和 CSS 的函数:

close: function() {
var modal = Polymer.dom(this.root).querySelector(".modal");
//modal.style.display = "none";
modal.classList.add('hide');

}

这是我的样式表:

<style>
@keyframes show {
0% {
display: none;
opacity: 0;
}
1% {
display: block;
}
100% {
display: block;
opacity: 1;
}
}
@keyframes hide {
0% {
display: block;
opacity: 1;
}
99% {
display: block;
}
100% {
display: none;
opacity: 0;
}
}
.element, .element-css {
animation: show 500ms linear;
animation-fill-mode: forwards;
}
.hide{
animation: hide 500ms linear;
animation-fill-mode: forwards;
}
</style>

最佳答案

你可以试试这个

  Polymer({
is: 'my-dialog',
behaviors: [
Polymer.NeonAnimationRunnerBehavior
],
properties: {
opened: {
type: Boolean
},
animationConfig: {
value: function() {
return {
'entry': {
// provided by neon-animation/animations/scale-up-animation.html
name: 'scale-up-animation',
node: this
},
'exit': {
// provided by neon-animation-animations/fade-out-animation.html
name: 'fade-out-animation',
node: this
}
}
}
}
},
listeners: {
'neon-animation-finish': '_onNeonAnimationFinish'
},
show: function() {
this.opened = true;
this.style.display = 'inline-block';
// run scale-up-animation
this.playAnimation('entry');
},
hide: function() {
this.opened = false;
// run fade-out-animation
this.playAnimation('exit');
},
_onNeonAnimationFinish: function() {
if (!this.opened) {
this.style.display = 'none';
}
}
});

HTML

<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content" >
<div class="modal-header">
<a class="close button">

<paper-button raied type="button" class="close" id="close" aria-hidden="true" on-click="close">Close</paper-button>
</a>
<h2 class="modal-title">Title</h2>
</div>
<div class="modal-body next">
<img class='modal-img' />
</div>
<div class="modal-footer">
<paper-button raied id="previous" type="button" class="pull-left prev" on-click="prev">Previous</paper-button>
<paper-button raied id="next" type="button" class="next" on-click="next">Next</paper-button>
</div>
</div>
</div>
</div>

您还可以查看 jsfiddle link

关于javascript - 如何使用纯 javascript 显示和隐藏模态对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33908689/

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