简体   繁体   English

黑色透明覆盖在 UI 中有一些干扰 - CSS

[英]Black transparent overlay has some disturbance in UI - CSS

I've created a custom modal popup box.我创建了一个自定义模式弹出框。 To show or hide the modal box, I've used JQuery code.为了显示或隐藏模式框,我使用了 JQuery 代码。 Below is my CSS style code and JQuery code下面是我的 CSS 样式代码和 JQuery 代码


CSS CSS

    .overlay {
        position: fixed;
        background: #000;
        opacity: .8;
        height: 100%;
        width: 100%;
        display:none;
        z-index: 999
    }

 .modal {
     position: absolute;
    margin: 30px auto;  
    background: #fff;
    display:none;
    height: 200px; 
    width:600px;
    top: 60px;     
  }


JQuery Code:查询代码:

function showModal(){
   $('.overlay').show(); 
   $('.modal').fadeIn(100);
}


HTML Code: HTML代码:

<div class="overlay"></div>
<div class="modal">
   <div class="modal_title">My Title</div>
   <div class="modal_inner">
       My Modal Content
   </div>
</div>

Now, it's showing below output.现在,它显示在输出下方。
在此处输入图片说明 在此处输入图片说明

I want to remove this disturbance from UI.我想从 UI 中消除这种干扰。 But need to know why it's appearing?但需要知道它为什么会出现? Is my code wrong?我的代码错了吗? or Is there any other possibilities of this issue?或者这个问题还有其他可能性吗? How can I solve it?我该如何解决?

This is definitely not something caused by your code, but by the browser.这绝对不是由您的代码引起的,而是由浏览器引起的。 Confirm by trying to use other browsers too.也尝试使用其他浏览器进行确认。

There unfortunately isn't much you can do.不幸的是,您无能为力。 You can wait for them to fix it, or you can try a different approach which happens to not screw up with the rendering, but those are the only options as I see it.您可以等待他们修复它,或者您可以尝试不同的方法,该方法恰好不会搞砸渲染,但在我看来,这些是唯一的选择。

I suppose that you want to achieve something like this:我想你想实现这样的目标:

 $('.overlay').show(400, function() { $(this).append($('.modal')); $('.modal').fadeIn(1000) });
 .overlay { position: fixed; background: #000; opacity: .8; height: 100%; width: 100%; display: none; z-index: 999; } .modal { position: absolute; margin: 30px auto; background: #fff; display: none; height: 200px; width:600px; top: 60px; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="overlay"></div> <div class="modal"> <div class="modal_title">My Title</div> <div class="modal_inner"> My Modal Content </div> </div>

You should use callbaks in order to make it work consecutively like overlay -> modal.您应该使用 callbaks 以使其像覆盖-> 模态一样连续工作。 That disturbance is related to fading in your modal - it is hapenning at the same time as the overlay appeares.这种干扰与您的模式中的淡入淡出有关 - 它与叠加层出现的同时发生。 They overlap and get animated so we see some weird visual effect related to page rendering while animating.它们重叠并被动画化,所以我们在动画时看到了一些与页面渲染相关的奇怪视觉效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM