简体   繁体   English

提高iPad上的CSS3速度

[英]Improve CSS3 speed on iPad

iOS overall tends to suck with CSS3 transitions, animations, transforms, etc. Which IMO are some of the best features of the tech. iOS整体往往会受到CSS3过渡,动画,变换等的影响。哪种IMO是该技术的一些最佳功能。

Now, I've heard that you can trick iOS into initializing its hardware acceleration by throwing in some random 3D transforms and what not. 现在,我听说你可以通过投入一些随机的3D变换来欺骗iOS来初始化它的硬件加速。 So I transformed a random div and put it on screen (didn't even hide it), and the experience still chugs along... 所以我改造了一个随机的div并把它放在屏幕上(甚至没有把它隐藏起来),而且经验仍然随之而来......

Is there any way to improve the performance of CSS3 transitions, transforms, animations, etc. on the iOS? 有没有办法在iOS上提高CSS3过渡,转换,动画等的性能? Or are web apps doomed to be plastic-y knock-offs of native apps? 或者,网络应用程序注定要成为本机应用程序的塑料吗?

Edit: Here's the offending code... 编辑:这是有问题的代码......

http://www.abhi.my/sl/html/ http://www.abhi.my/sl/html/

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... 只需按照这个链接,你就会看到我放在一起的一个小小的演示......当在桌面浏览器上观看时,动画很流畅且可以接受,iOS上的同一个网站受到了影响......这个版本适用于iPhone 4 ...

Feel free to go through the source and point things out... 随意浏览消息来源并指出问题......

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. 3D变换在iOS上是硬件加速的,所以你要做的就是在你做的时候使用3D语法,并且它表现很好 - 至少在3GS及以上。

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. 但是你没有在你的例子中使用变换,你正在使用位置转换,这是完全不同的,是的 - 导致移动设备上的蹩脚fps。

Instead, you should be using -webkit-transform: translate3d(-100%,0,0) (or a suitable analog). 相反,您应该使用-webkit-transform:translate3d(-100%,0,0)(或合适的模拟)。 You can see how much smoother this is from the example in this page. 您可以在此页面的示例中看到它的平滑程度

You should definitely use -webkit-transform rather than -webkit-transition. 你绝对应该使用-webkit-transform而不是-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. 话虽如此,对于跨浏览器支持和易用性,我肯定会使用jQuery Transit这样的插件,它允许您轻松地在iOS以及Android和其他移动设备上创建流畅的,原生的过渡和效果。

Example JSFiddle of jQuery Transit in action JSQuery Transit的JSFiddle实例

Code Example: 代码示例:

HTML: HTML:

<div class="moveMe">
    <button class="moveUp">Move Me Up</button>
    <button class="moveDown">Move Me Down</button>
    <button class="setUp">Set Me Up</button>
    <button class="setDown">Set Me Down</button>
 </div>

Javascript: 使用Javascript:

$(".moveUp").on("click", function() {
    $(".moveMe").transition({ y: '-=5' });
});

$(".moveDown").on("click", function() {
    $(".moveMe").transition({ y: '+=5' });
});

$(".setUp").on("click", function() {
    $(".moveMe").transition({ y: '0px' });
});

$(".setDown").on("click", function() {
    $(".moveMe").transition({ y: '200px' });
});

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. 我无法忍受修补CSS3动画,这个插件令人惊讶地完成了它的工作。 I have tested this with an iPad, iPod Touch, iPhone, and Android. 我用iPad,iPod Touch,iPhone和Android测试了这个。 I love the native feel it gives. 我喜欢它给人的本土感受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM