提高 iPad 上的 CSS3 速度
iOS 总体上在 CSS3 过渡、动画、变换等方面表现不佳。在我看来,这是该技术的一些最佳功能。
现在,我听说你可以通过引入一些随机 3D 变换等来欺骗 iOS 来初始化其硬件加速。所以我随机变换了一个 div 并将其放在屏幕上(甚至没有隐藏它),但体验仍然很糟糕...
有什么方法可以提高 iOS 上 CSS3 过渡、变换、动画等的性能?或者说网络应用程序注定会成为原生应用程序的仿制品?
编辑:这是有问题的代码...
http://www.abhi.my/sl/html/< /a>
只需点击该链接,您就会看到我放在一起的一个小演示...在桌面浏览器上查看时,动画很流畅且可以接受,iOS 上的同一网站则受到影响...这个是为iPhone 4...
随意查看源代码并指出一些事情...
iOS overall tends to suck with CSS3 transitions, animations, transforms, etc. Which IMO are some of the best features of the tech.
Now, I've heard that you can trick iOS into initializing its hardware acceleration by throwing in some random 3D transforms and what not. So I transformed a random div and put it on screen (didn't even hide it), and the experience still chugs along...
Is there any way to improve the performance of CSS3 transitions, transforms, animations, etc. on the iOS? Or are web apps doomed to be plastic-y knock-offs of native apps?
Edit: Here's the offending code...
Just follow that link, and you'll see a little demo I put together... The animations are smooth and acceptable when viewed on a desktop browser, the same site on the iOS suffers... This one was intended for the iPhone 4...
Feel free to go through the source and point things out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
3D 变换在 iOS 上是硬件加速的,因此您所要做的就是在执行此操作时使用 3D 语法,并且它的性能非常好 - 至少在 3GS 及更高版本上。
但是您在示例中没有使用变换,而是在位置上使用过渡,这是完全不同的,是的 - 导致移动设备上的帧速率很差。
相反,您应该使用 -webkit-transform:translate3d(-100%,0,0) (或合适的类似物)。您可以从本页中的示例中看到这有多流畅。
3D transforms are hardware-accelerated on iOS, so all you have to do is use the 3D syntax whenever you're doing it, and it performs great - at least on 3GS and above.
But you are not using transforms in your example, you are using a transition on position, which is completely different, and yes - results in crappy fps on mobile.
Instead, you should be using -webkit-transform: translate3d(-100%,0,0) (or a suitable analog). You can see how much smoother this is from the example in this page.
您绝对应该使用-webkit-transform而不是-webkit-transition。话虽如此,为了跨浏览器支持和易用性,我肯定会使用 jQuery Transit< /a> 允许您在 iOS 以及 Android 和其他移动设备上轻松创建平滑、类似本机的过渡和效果。
jQuery Transit 的 JSFiddle 实际应用
代码示例:
HTML:
Javascript:
其他人已经为你完成了大部分艰苦的工作。我无法忍受修改 CSS3 动画,而这个插件的工作效果令人惊叹。我已经使用 iPad、iPod Touch、iPhone 和 Android 对此进行了测试。我喜欢它给人的原生感觉。
You should definitely use -webkit-transform rather than -webkit-transition. With that said, for cross-browser support and ease of use, I would definitely go with a plugin such as jQuery Transit that allows you to easily create smooth, native-like transitions and effects on iOS as well as Android and other mobile devices.
Example JSFiddle of jQuery Transit in action
Code Example:
HTML:
Javascript:
Someone else has pretty much done the hard work for you. I can't stand tinkering with CSS3 animations and this plugin does its job amazingly. I have tested this with an iPad, iPod Touch, iPhone, and Android. I love the native feel it gives.