CSS3 过渡 +不显示 +防止过度滚动
因此,如果您还不熟悉的话,CSS3 过渡不会对 display: none
进行动画处理,因为它会从 DOM 中完全删除目标元素。这是我的问题。我有一个侧边栏,其中悬停时会出现更大的弹出 div。不幸的是,由于我只能在 visibility: hide
和 opacity: 0
上进行转换,因此由于布局中包含明显隐藏的 div,因此我出现了过度滚动,从而产生了一个非常长的弹出窗口占页面的滚动条。
寻找一些创造性的解决方案,以了解如何在不将滚动条搞砸的情况下仍然可以制作动画。
我正在本地开发,所以我没有可以展示的实时示例,但您可以在此截屏视频中看到问题: http://dreamstarstudios.com/screencasts/2011-09-27_2111.swf
提前致谢!
So if you're not already familiar, CSS3 transitions do not animate display: none
since it removes the targeted element from the DOM altogether. So here's my issue. I have a sidebar with larger popup divs that appear on hover. Unfortunately Since I can only transition on visibility: hidden
and opacity: 0
I have overscroll due to the visibly hidden divs being included in the layout and thus making a very long popup which is accounted for in the page's scrollbar.
Looking for some creative solutions for how I can still animate without having the scrollbar all screwed up.
I'm developing local so I don't have a live example to show, but you can see the problem in this screencast: http://dreamstarstudios.com/screencasts/2011-09-27_2111.swf
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的弹出窗口已绝对定位,因此您可以执行以下操作:
top
设置为一个巨大的负值。这会将其移出屏幕并摆脱滚动条。top
设置为正确的值并转换opacity
值。transition
规则仅适用于opacity
属性。HTML
CSS
这是上面的实际操作。
更新:要添加向左摆动,并清理鼠标移出动画,可以使用以下代码:
其执行方式如下:
transition-delay
防止顶部值发生更改,直到不透明度和左侧动画完成为止。这里的技巧是,当元素为:hover
时,没有延迟(不透明度、左侧和顶部动画全部立即开始)。但是,一旦:hover
不再处于活动状态,顶部动画会在开始之前等待 1 秒。这会产生不透明度并留出足够的时间来完成。这是更新的示例。
I'm assuming your popup is absolutely positioned so you could do the following:
top
to a huge negative value. This moves it off the screen and gets rid of the scrollbar.top
to the correct value and transition theopacity
value.transition
rules are only for theopacity
property.HTML
CSS
Here's the above in action.
Update: To add the left swing, and clean up the mouseout animation, you can use the following code:
It does this as follows:
transition-delay
prevents the top value from being changed until the opacity and left animations are complete. The trick here is that when the element is:hover
, there is no delay (opacity, left and top animations all start at once). However once:hover
is no longer active, the top animation waits 1 second before starting. This gives opacity and left enough time to finish.Here's the updated example.