jQuery:如何将高度添加到元素顶部,从而将动画设置为更高的高度?
我有一个简单的问题,但我不知道如何解决它。
基本上我有一些隐藏内容,一旦展开,需要 99px 的高度。折叠时,容纳它的元素 section#newsletter
的高度设置为 65px。
实例:http://dev.supply.net.nz/asap-finance- static/
单击 a#signup_form
时,section#newsletter
使用以下 jQuery 扩展到 99px:
$('#newsletter_form').hide(); // hide the initial form fields
$('#form_signup').click(function(event) {
event.preventDefault(); // stop click
// animate
$('section#newsletter').animate({height: 99}, 400, function() {
$('#newsletter_form').show(300);
})
});
所有这些都很好用,除了以下事实:元素位于粘性页脚中,因此它的初始高度用于定位它。
动画这个元素的高度会导致浏览器上出现滚动条,因为添加的 34px 被添加到元素的底部,所以我的问题:
如何将这些 34px 添加到元素的顶部,以便高度向上扩展到主体而不是向下?
感谢您的阅读, 我期待您的帮助和建议。
詹尼斯
I have a simple problem but I am not sure how to solve it.
Basically I have some hidden content that, once expanded, requires a height of 99px. While collapsed the element holding it section#newsletter
is set to be 65px in height.
LIVE EXAMPLE: http://dev.supply.net.nz/asap-finance-static/
On the click of a#signup_form
the section#newsletter
is expanded to 99px using the following jQuery:
$('#newsletter_form').hide(); // hide the initial form fields
$('#form_signup').click(function(event) {
event.preventDefault(); // stop click
// animate
$('section#newsletter').animate({height: 99}, 400, function() {
$('#newsletter_form').show(300);
})
});
All this works great except for the fact that this element sits in a sticky footer so its initial height is used to position it.
Animating the height of this element causes scrollbars on the browser, because the 34px added are added to the bottom of the element, so my question:
How can I add these 34px to the top of the element so the height expands upwards into the body not downwards?
Thanks for reading,
I look forward to your help and suggestions.
Jannis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了发布我的特定问题的完整解决方案,以防对其他人有所帮助,这里是代码:
JS:
CSS: (这是我正在使用的粘性页脚)
所以基本上我正在定位我的
页脚
,就像我通常使用 TOTAL 的完整高度一样(在动画高度之后),然后我通过 margin-top 下推初始内容,以补偿your_container
折叠时高度的较小值。然后在动画上调整
your_container
的高度以及your_container
和footer
上的边距顶部。.push
被删除。希望这对其他人偶然发现这一点时有所帮助。
J。
just to post the complete solution to my specific problem in case this may help others, here is the code:
JS:
CSS: (this is the sticky footer i am using)
So basically I am positioning my
footer
as I would normally with the full height of the TOTAL (after animation height) and then I push down the initial content via margin-top to compensate for the lesser value in height when theyour_container
is collapsed.Then on animate both the height of
your_container
is adjusted and the margin-top onyour_container
andfooter
&.push
are removed.Hope this helps someone else when they stumble upon this.
J.
你可以这样做:
You can do something like this: