webkit translate3d 问题(peek-thru)
我正在使用 PhoneGap 构建一个 iOS 应用程序。我使用translate3d CSS 动画来创建“翻转”效果。
这对于更简单的元素非常有用...带有前/后 div 的 DIV,可能还有一个或两个额外的跨度。
但是当我尝试翻转更大的元素......即整个屏幕时,我会遇到重绘故障。一旦我交换 css 类来开始转换,会发生什么,“底部”div 的一部分会弹出“顶部”div,然后发生翻转,然后再次弹出。而且它并不是显示整个元素...它是沿我正在执行平移 3d 旋转的轴分割的元素的一半。
关于可能导致这种情况的任何想法或理论?在 iPad 上作为应用程序以及在 Safari 桌面上发生的情况都是一样的,因此似乎是一个 webkit 问题。
会不会是一些 CSS 问题?或者尝试使用复杂的嵌套元素进行全屏translate3d 旋转,其中的大背景图像超出了Safari 可以处理的范围?
更新 1:
我在缩小问题范围方面取得了进展。
发生的情况是,当我执行translate3d 翻转时“窥视”的元素恰好是之前通过translate3d 定位的子元素。
我想用translate3d转换我的“页面”结构:
<div id="frontbackwrapper">
<div id="front">
</div><!--/front-->
<div id="back">
</div><!--/back-->
</div><!--/frontbackwrapper-->
这可以单独工作。前面的 div 被后面的 div 替换,具有卡片翻转的效果。
问题是,在进行整页翻转之前,我已经使用 translate3d 对 #front
div 中的一些元素进行了动画处理:
<div id="frontbackwrapper">
<div id="front">
<div class="modal"></div>
</div><!--/front-->
<div id="back">
</div><!--/back-->
</div><!--/frontbackwrapper-->
示例 CSS:
.modal {
width: 800px;
height: 568px;
position: absolute;
left: 112px;
z-index: 100;
-webkit-transition-duration: 1s;
-webkit-transform: translate3d(0,-618px,0); /* set off screen by default */
}
.modal.modalOn {
-webkit-transform: translate3d(0,80px,0); /* slides the div into place */
}
如果 - 而不是使用 translate3d - 我只是重新定位div 具有 top
样式或转换 top
属性,我没有遇到透视问题。当然,这意味着我必须分别放弃流畅的动画或硬件加速。
此时,它看起来像是一个 webkit bug。我会继续玩它。如果有人以前遇到过这个问题并找到了解决方法,我洗耳恭听!
I'm building an iOS app with PhoneGap. I'm using translate3d CSS animations to create the 'flip' effect.
This works great on simpler elements...a DIV with front/back divs and maybe an extra span or two.
But when I attempt to flip a larger element...namely the entire screen, I get redraw glitches. What happens as soon as I swap the css class to start the transition, parts of the 'bottom' div pop-through the 'top' div, then the flip happens, then they pop-out again. And it's not the entire element that shows through...it's half of the element split along the axis that I'm doing the translate 3d rotation on.
Any ideas or theories as to what might be causing this? It happens the same both on the iPad as an app and on the desktop in Safari, so appears to be a webkit issue.
Could it be some CSS issues? Or is attempting to do a full-screen translate3d rotation with complex nested elements with large background images just more than Safari can handle?
UPDATE 1:
I've made progress in narrowing down the issue.
What's happening is that the elements that are 'peeking through' when I do the translate3d flip happen to be child elements that had been previously positioned via translate3d.
My 'page' structure that I want to transition with translate3d:
<div id="frontbackwrapper">
<div id="front">
</div><!--/front-->
<div id="back">
</div><!--/back-->
</div><!--/frontbackwrapper-->
This works on it's own. The front div is replaced with the back div with a card-flip effect.
The problem is that prior to doing the full page flip, I've already animated some elements within the #front
div using translate3d:
<div id="frontbackwrapper">
<div id="front">
<div class="modal"></div>
</div><!--/front-->
<div id="back">
</div><!--/back-->
</div><!--/frontbackwrapper-->
Example CSS:
.modal {
width: 800px;
height: 568px;
position: absolute;
left: 112px;
z-index: 100;
-webkit-transition-duration: 1s;
-webkit-transform: translate3d(0,-618px,0); /* set off screen by default */
}
.modal.modalOn {
-webkit-transform: translate3d(0,80px,0); /* slides the div into place */
}
If--instead of using translate3d--I just reposition the div with a top
style or transform the top
property, I don't get the peek-through issue. Of course, that means I have to give up the slick animation or hardware acceleration, respectively.
At this point, it looks like a webkit bug. I'll keep doing some playing with it. If anyone has run into this before and found a workaround, I'm all ears!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案!经过一夜的睡眠,我思考了罪魁祸首以及该如何处理。这不一定是使用translate3d 为子元素设置动画的行为,而是被翻译的元素在使用translate3d 对其父元素进行动画处理时具有该CSS 属性的情况。
解决方法是首先为子元素设置动画,然后一起删除翻译样式。
CSS 结构现在是:
和一些示例 jQuery:
有点乏味,但它完全解决了屏幕重绘问题。
编辑:更正拼写错误
solution! After a night of sleep, I mulled over the culprit and what to do with it. It's not necessarily the act of animating a child element with translate3d but rather the face that the element that was translated has that CSS property at the time it's parent is being animated with translate3d.
The fix is to first animate the child element, then remove the translate style all together.
The CSS structure is now:
And some sample jQuery:
A little tedious, but it completely fixes the screen redrawing problem.
EDIT: Corrected a typo
DA,
我从这件事中学到了一些东西,谢谢。还,
记下 css 属性“translate3d”和“left”。翻译和定位有点不同。测试一下,将元素在 x 轴上平移 100px,将其“left”样式属性设置为 0px。验证一下,它将位于 x 轴上距当前平移点 0px 的位置(从 x 轴上的 100px 开始)。
这会在拖放和动画算法中产生数学错误,并且很容易注意到(重绘故障、跳过、位置重置),并且成为一个挑战,因为 translate3d 不再更新元素 offsetLeft 或 'left' 样式属性(以防止回流,以进行优化) ),因此解析真正左侧的元素是基于了解是否使用了translate3d或left。如果您是游戏开发人员,跟踪内部变量中的 x,y 是与元素位置保持同步的方法。希望能提供更多帮助。
DA,
I learned something from this, thanks. Also,
take note of the css attrbibutes, 'translate3d' and 'left'. Translating and positioning is a little different. Test it out, translate an element 100px in x-axis, set it's 'left' style attribute to 0px. Verify, it will be positioned at 0px on x-axis from the current translation point (starting from 100px on x-axis).
That produces mathematical errors in drag/drop and animation algorithms and easily noticed (redraw glitches, skips, position getting reset), and becomes a challenge because translate3d no longer updates the elements offsetLeft or 'left' style attribute (to prevent reflow, for optimization), so parsing the elements real left, is based on knowing if translate3d or left was being used. If you're a game developer, tracking the x,y in internal variables is the way to stay in synch with the elements position. Hope that helps out more.