使用 jQuery 在单击时对宽度和高度进行动画处理
尝试在单击时对这些框的宽度和高度进行动画处理。
请参阅小提琴:
我已经成功获得动画的宽度...不只是需要防止动画结束时尴尬的跳跃。
编辑:
值得注意的是,我无法在 li 上设置静态高度
Trying to animate both the width and the height of these boxes on click.
See fiddle:
I've been successful with getting the width to animate... no just need to prevent that awkward jump at the end of the animation.
edit:
worth noting I cannot set a static height on the li's
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
200 是多少?在他们?像素?使用测量。 '200px'。
您没有为高度和宽度设置动画:{width: '200px', height: '200px'}
我删除了自动高度的 .active css 规则。动画需要解决这个问题。
代码:
我有时使用这个 hack 来计算动态高度:
你需要确保 CSS 不会搞乱这个。
基本上,您创建具有最终宽度的元素,计算其高度,然后将其删除。此函数将返回一个数字,您需要添加
px
并可以在动画中使用它。但是你并不真的需要这个。高度会自动为你制作动画,你的 CSS 规则只是禁用了它。例如,这个小提琴就可以正常工作。
What's 200? in em? px? use a measurement. '200px'.
You didn't animate the height as well as the width: {width: '200px', height: '200px'}
I dropped the .active css rule for auto height. The animation needs to take care of that.
code:
I sometimes use this hack for figuring out a dynamic height:
You need to make sure the CSS doesn't mess this up.
Basically you create the element with the final width, calculate its height and then remove it. This function will return a number, you'll need to add
px
and you can use it in your animation.But you don't really need this. Height animates automatically for you, your CSS rules just disabled it. For example, this fiddle will work just fine.
要对高度进行动画处理,只需在动画调用中的宽度下方添加一个高度值即可。
最后的跳转是由浏览器尝试自动重新布局所有元素引起的。为了防止这种情况,您应该将它们全部放入网格中,然后在每次动画完成时重新布局网格。
To animate the height, just add a height value under the width in the animate call.
That jump at the end is caused by the browser trying to automatically re-layout all the elements. In order to prevent that, you should put them all into a grid, then re-layout the grid each time the animation finishes.
css 上的这一行导致了跳转。
尝试删除“display:block”属性,它应该会顺利进行。找到一种方法来补救该元素。这应该很容易。
This line on your css is causing the jump.
Try removing the "display:block" property and it should went smoothly. Find a way to have a remedy for that element. It should be easy.