Javascript jQuery slideDown 不流畅
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10471202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery slideDown is not smooth
提问by user13746
I have this little jQuery slideDown effect http://jsfiddle.net/Gg4eP/2/
我有这个小小的 jQuery slideDown 效果http://jsfiddle.net/Gg4eP/2/
But the animation isn't smooth? What I am doing wrong?
但是动画不流畅?我做错了什么?
Thanks for your time.
谢谢你的时间。
回答by Gregg B
You just need to add the width to each expandable div.
您只需要为每个可扩展的 div 添加宽度。
To explain:
解释:
jQuery doesn't know the dimensions of your hidden div until it's displayed. So when it's clicked on it actually pulls it out of position to measure it before quickly replacing it. This often has the side effect of causing some jumpiness. Setting the width on the element prevents jQuery from pulling it out of position.
jQuery 不知道隐藏 div 的尺寸,直到它显示出来。因此,当它被点击时,它实际上会在快速更换之前将其拉出位置以进行测量。这通常具有引起一些跳跃的副作用。在元素上设置宽度可防止 jQuery 将其拉出位置。
回答by adeneo
Some browsers don't particularly like text that is automaticly wrapped when animating, and it gets a little jerky when it tries to figure out the height of the element.
一些浏览器并不特别喜欢动画时自动换行的文本,并且当它试图计算元素的高度时会变得有点生涩。
Try formatting the text to fit the element and see if that helps.
尝试格式化文本以适合元素,看看是否有帮助。
I actually did it for you, check if this FIDDLEsolves it ?
我实际上是为你做的,检查这个FIDDLE 是否解决了它?
Would probably work to give the slided elements a fixed height aswell ?
可能也会给滑动元素一个固定的高度?