【发布时间】:2021-09-24 14:19:07
【问题描述】:
这可能最好用一个例子来说明。我有一个parent 和一个child。默认情况下,父级是隐藏的,除非它具有 in 类。只有在父级收到in 类后,其子级才应在 3 秒延迟后将其background-color 从绿色转换为白色。
所以当显示父级时,子级的背景色已经是白色了。没有 3 秒的橙色,过渡到白色。有人可以解释这里发生了什么吗?
$('button.show').on('click', () => {
$('.parent').addClass('in');
});
$('button.hide').on('click', () => {
$('.parent').removeClass('in');
});
.parent, .child {
display: flex;
align-items: center;
justify-content: center;
}
.parent {
background-color: orange;
width: 300px;
height: 300px;
}
.child {
background-color: green;
padding: 20px;
width: 150px;
height: 150px;
transition: background-color 1s linear;
}
.parent:not(.in) {
display: none;
}
.parent.in .child {
background-color: white;
transition-delay: 3s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent">
<div class="child">
<span>Background should start green, then turn white, but transition isn't happening.</span>
</div>
</div>
<br>
<button type="button" class="show">Show parent</button>
<button type="button" class="hide">Hide parent</button>
【问题讨论】:
标签: css css-transitions css-transforms