修复 jQuery SlideDown 动画末尾的垂直跳跃
我是 Jquery 的新手,但写了一个简单的垂直手风琴。这似乎符合我所要求的工作,但在滑落结束时有明显的抖动。
如果有人能看一下它并提出一个解决方案,这将阻止我再拔头发!
这是我的测试页面的链接(为了方便起见,我的所有代码 [css、js 等] 都在一个文件中): 垂直手风琴
I am new to Jquery but have written a simple vertical accordion. It seems to to the job I require, but at the end of the slide down there is a visible jerk.
If anyone could look at it and suggest a solution, it will stop me pulling any more of my hair out!
Here is a a link to my test page (all my code [css, js etc.] is in one file for ease) : Vertical Accordion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的自定义代码中,我通过对 CSS 进行小更改并指定手风琴中 p 标签的高度来摆脱“跳转”。
由于您通过脚本将它们全部隐藏,因此在执行之前:
也许您可以遍历并获取每件的计算高度并将其添加到每个项目样式中,从而消除最后遇到的“混蛋”。
沿着这些思路的事情:
编辑
我继续下载了您的页面的副本并对其进行了测试,它似乎在一些快速浏览器测试中工作正常,所以这是您修改后的 vaccordian.js:
TL;DR - 通过设置明确的高度在手风琴的每个“打开”部分,它消除了抖动动画。所以我们通过脚本设置这些高度。
In your custom code, I got rid of the 'jump' by making a small change in the CSS and specifying the height of the p tags within the accordion.
Since you hide them all via script, before you do:
maybe you could walk through and get the calculated heights of each piece and add that to each items style, thereby eliminating that "jerk" you get at the end.
Something along these lines:
Edit
I went ahead and downloaded a copy of your page and tested this, and it seems to work fine in a few quick browser tests, so here's your revised vaccordian.js:
TL;DR - by setting an explicit height on each 'opening' part of the accordion, it removes the jerky animation. so we set those heights via script.
作为参考,以防其他人遇到此问题,以下内容对我有用:
我真的没有时间调查此修复程序为何有效的细节,但我想无论如何我都会分享。
For reference in case somebody else comes across this problem, the following worked for me:
I don't really have time to investigate the details of why this fix works, but thought I'd share anyway.
我只需使用
overflow: auto
或overflow: hide
就可以解决我的问题。我认为这是有效的,因为它忽略了元素的高度并会显示它可以显示的任何内容。只要高度不小,它就应该能够显示所有内容,但添加溢出属性可以使其过渡更平滑,因为它不计算高度。I was able to fix my problem just by using
overflow: auto
oroverflow: hidden
. I think this works because it ignores the height of the element and will show whatever it can. As long as there isnt a small height it should be able to show everything but adding theoverflow
property allows it transition more smoothly because it is not calculating the height.