绝对定位元素上同时淡入/淡出的 JQuery 错误
我有一组元素想要一个接一个地显示,淡出第一个元素,同时淡入第二个元素,并在到达最后一个元素时循环它们
如果我绝对定位第一个元素,同时淡出,第二个元素不会定位没有任何问题,除非是最后一个。有一个错误(?)使最后一个项目(应该淡出)在将位置设置为绝对位置后使用空间,就好像它具有相对位置一样。
您可以在此处查看该错误: http://jsfiddle.net/XekVc/
Chrome 12.0 中存在此行为(我认为是最后一个版本)和 FF 3.6.17
我不想让它们全部绝对定位,因为我的应用程序中的容器有其他相对定位的元素,我必须在此之后调整,所以这是我的最后一个选择。
有谁知道这是我的代码中的错误,还是 jquery/浏览器的渲染引擎问题?
I have a collection of elements I want to show one after another, fading out the first while fading in the second simultaneously, and cycle them when reaching the last one
If I position absolutely the first element, while fading out, the second one doesn't have any problems positioning, EXCEPT if it is the last one. There is a bug (?) that makes the last item, that should be fading out, to use the space as if it has a relative position, after setting the position to absolute.
You can see the bug here: http://jsfiddle.net/XekVc/
This behavior is present in Chrome 12.0 (I think is last version) and FF 3.6.17
I don't want to make all of them absolutely positioned, since the container in my application has other relatively positioned elements which I would have to adjust after this, so it is my last alternative.
Does anyone have an idea if this is a bug on my code, or is this a jquery / browser's render engine issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在玩小提琴时,我可以通过在更改其位置之前执行
element.prependTo(element.parent())
将离开的元素放置在即将到来的元素之前来避免该错误。http://jsfiddle.net/e253r/
这可能是一种解决方法,但我仍然真正感兴趣找出它是否是一个错误以及在哪里......
Playing with the fiddle, I can avoid the bug by placing the leaving element before the coming one, by doing a
element.prependTo(element.parent())
before changing its positioning.http://jsfiddle.net/e253r/
This can be a workaround, but I'm still genuinely interested in finding if it is a bug and where...
编辑所以我决定查看
.animate()
路线:http://jsfiddle.net/XekVc/16/
似乎有效
EDIT so I decided to check out the
.animate()
route:http://jsfiddle.net/XekVc/16/
seems to work
不知道为什么会发生这种情况。除了绝对定位还能设置top:0吗?容器位置也必须设置
http://jsfiddle.net/XekVc/17/
Not sure why this happens. Can you set top: 0 in addition to absolute positioning? The container position would have to be set too
http://jsfiddle.net/XekVc/17/