简体   繁体   English

CSS3:翻译vs. translationX

[英]CSS3: translate vs. translateX

I was looking over the source code to swipe.js , a cross-browser library for creating animated slideshows on devices that support touch. 我正在查看swipe.js的源代码, swipe.js是一个跨浏览器的库,用于在支持触摸的设备上创建动画幻灯片。

To create the animation, swipe.js uses CSS3 transforms (and falls back on Javascript animation if it has to.) So, the translate function they use to do the actual CSS3 transform is: 要创建动画,swipe.js使用CSS3转换(如果需要的话,可以使用Javascript动画。)因此,它们用来执行实际CSS3转换的转换函数是:

 function translate(index, dist, speed) {

    var slide = slides[index];
    var style = slide && slide.style;

    if (!style) return;

    style.webkitTransitionDuration =
    style.MozTransitionDuration =
    style.msTransitionDuration =
    style.OTransitionDuration =
    style.transitionDuration = speed + 'ms';

    style.webkitTransform = 'translate(' + dist + 'px,0)' + 'translateZ(0)';
    style.msTransform =
    style.MozTransform =
    style.OTransform = 'translateX(' + dist + 'px)';

  }

So, basically in order to make this cross-browser, they have to set different transform properties for Webkit, Mozilla, Microsoft and Opera. 因此,基本上,为了制作此跨浏览器,他们必须为Webkit,Mozilla,Microsoft和Opera设置不同的转换属性。 What I don't understand is why they use the translate function (which takes two arguments) for webkit, and the single-argument translateX function for everything else. 我不明白的是为什么他们对Webkit使用了translate函数(需要两个参数),而对其他所有函数都使用了单参数的translateX函数。

As far as I can see from the Mozilla and Microsoft documentation, both engines support translate as well as translateX . 据我从MozillaMicrosoft文档中所看到的,两个引擎都支持translate以及translateX Is there some reason the author of swipe.js decided to use translateX for non-webkit browsers here? swipe.js的作者决定在此处translateX非Webkit浏览器使用translateX是否有某些原因? Is there actually some browser out there that supports translateX but NOT translate ? 实际上,那里是否存在一些支持translateX但不translate浏览器?

Looks like this has historical reasons, by the time support for Firefox, Opera and IE was added , they all supported only 2d transforms . 看起来这是有历史原因的,到添加Firefox,Opera和IE的 支持时 ,它们都仅支持2d转换 Support for 3d transforms was added a few months later in firefox , and IE10 also supports it, so it's actually only still neccessary for Opera, but I guess it's left there for backwards compatibility. 几个月后,在firefox中添加了对3d变换的支持,并且IE10也支持它,因此对于Opera而言,它实际上仍然仍然是必需的,但是我想它是向后兼容的。

Update 更新资料

Oops, thought I've read translate3d , but in the later verions it's only translate , just like you've posted it. 糟糕,以为我已经阅读了translate3d ,但在以后的版本中,它仅是translate ,就像您已将其发布一样。 So, it looks like they've changed to translate + translateZ because translate3d would no longer trigger hardware acceleration in iOS6 , maybe there are similar problems with translateX . 因此,它看起来就像他们已经改为translate + translateZ因为translate3d不再触发在iOS6的硬件加速功能 ,也许有类似的问题translateX

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

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