我想要动画展示子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 Snippet。外部链接是可以的,但仅当相关代码也在此处包含时,因为外部链接可能会随时间而中断或更改,这个问题对其他用户不再有用。另外,您所询问的内容有点不清楚 - 您所说的“在父级之外动画”是什么意思?如果您不想重叠父级,请将其从子级更改为同级。 - FluffyKitten