【发布时间】:2020-12-27 08:27:33
【问题描述】:
我想为子 div 的宽度设置动画以脱离父 div。 在我链接孩子的代码中,div 在父 div 内部而不是在其外部进行动画处理。
请帮忙。 jsfiddle
$(document).ready(() => {
drop = false;
$(".parent").click(() => {
if (drop == true) {
$(".child").animate({
width: "0px"
});
drop = false;
} else if (drop == false) {
$(".child").animate({
width: "200px"
});
drop = true;
}
})
});
.parent {
width: 40%;
height: 200px;
position: relative;
background-color: red;
}
.child {
width: 0px;
height: 200px;
position: absolute;
right: 0;
top: 0;
background-color: aqua;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent">
<div class="child">
</div>
</div>
【问题讨论】:
-
欢迎来到 Stack Overflow。请参阅 How to Ask 和 edit 您的问题以包含您的代码。您可以使用编辑器工具栏上的
[<>]按钮创建可运行的堆栈片段。外部链接是可以的,但仅当相关代码也包含在此处时,因为外部链接可能会随着时间的推移而中断或更改,并且该问题对其他用户不再有用。另外,您要问的有点不清楚-“在父母之外制作动画”是什么意思?如果你不想重叠父母,你能不能把它从孩子改成兄弟姐妹?
标签: html jquery css jquery-animate