gpt4 book ai didi

javascript - 使用 JQuery/CSS 动画增加 div 的大小

转载 作者:行者123 更新时间:2023-11-30 11:46:02 25 4
gpt4 key购买 nike

我有一个包含两个部分的简单网站。理想情况下,顶部的部分将以特定大小加载,但随后通过单击位于该部分底部的按钮,该部分将增加大小以适合屏幕。如果再次单击该部分将返回到其原始大小。

功能应该与本网站上的完全一样:

http://www.urbandisplacement.org/map/la

我有几个问题:

  1. 通过 JQuery/CSS 实现这种效果的最佳方法是什么?
  2. 如何确保按钮固定在增大/缩小的 div 底部并随着 div 移动?

我尝试过使用 JQuery 在单击按钮时重置顶部 div 的高度,但这既不会在使用按钮时使按钮动画也不会将其保留在 div 的底部。

谢谢!

最佳答案

这是一个简单的纯 CSS 版本:

https://jsfiddle.net/otenf0fy/

body,#wrapper {
height: 100%;
}
#expand {
display: none;
}
#top {
background: black;
color: white;
padding: 1em;
position: relative;
}
label {
background: blue;
color: white;
border-radius: .5em;
padding: 1em;
display: block;
width: 5em;
text-align: center;
cursor: pointer;
position: absolute;
bottom: 1em;
left: 50%;
transform: translate(-2.5em,0);
}
#expand:checked ~ #top {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<body>
<div id="wrapper">
<input id="expand" type="checkbox">
<div id="top">
<p>
This is just a test
</p>
<label for="expand">Expand</label>
</div>
</div>
</body>

关于javascript - 使用 JQuery/CSS 动画增加 div 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40942469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com