css - append 模态 : how to fadeIn the background (parent) but not the modal content (child)

标签 css background modal-dialog append

我正在使用 append 模式登录表单的 WP 插件。我正在寻找一种仅将背景颜色从透明淡化为 rgba(0,0,0.9) 的方法,但我希望模态内容直接出现,没有淡化效果。我试过这个:

transition: background-color 2s ease;

但它不起作用。代码如下所示:

HTML

<button>click</button>

CSS

.modal {   
    background-color: rgba(0, 0, 0, 0.9);
    height: 100%;
    left: 0;
    position: fixed;
    top: 0;
    transition: background-color 2s ease;
    width: 100%;
} 

JS

$("button").click(function() {
  $("body").append(
  "<div class='modal'>" +
    "<div class='modal-content'>HELLO WORLD!</div>" +
  "</div>");
}); 

完整代码 HERE

我花了几个小时寻找可行的解决方案但没有成功:/有什么想法吗?

最佳答案

我找到了一个可行的解决方案(现在看起来很明显 :p ):

$("button").click(function() {
 $(".modal").fadeIn().css("background-color","rgba(0, 0, 0, 0.9)");
});

关于css - append 模态 : how to fadeIn the background (parent) but not the modal content (child),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44578351/

相关文章:

javascript - jQuery 中的样式代码不起作用

HTML/CSS : How to align link to another website to Center of Webpage --> Tried Align Link to Center in CSS . .. 无效

iphone - iPhone中如何设置表格背景透明?

c++ - 对话框操作中的断言错误

c++ - 使用 ESC 键关闭 Carbon 模式对话框

html - 如何自定义 tumblr 404 URL 未找到页面

html - CSS 表格样式

css - CSS 背景 URL 可以传递动态查询字符串吗?如果可以,如何传递?

css - JavaFX TableView 背景图片

javascript - Mozilla firefox 不再支持 dialog.showModal