【问题标题】:CSS3 animation translate3d not workingCSS3动画translate3d不起作用
【发布时间】:2012-11-13 13:21:35
【问题描述】:

我一直在试验 jQuery animate 与 CSS3 animate,我还想测试 2D / 3D 转换,看看哪个更好。

有人知道为什么我的 CSS3 translate3d 不起作用吗?我在台式机和移动设备上都试过了。

任何帮助表示赞赏

jsFiddle

HTML

<div id="container1" class="container">transition</div>
    <div id="container2" class="container">translate</div>
    <div id="container3" class="container">translate3d</div>
    <div id="container4" class="container">jQ animate</div>

CSS

    .container          {position:absolute; left:20px; width:80px; height:80px; padding:5px;}

/* transition */
#container1         {top:20px; background:red;
                    -webkit-transition:all 0.3s linear;
                    -moz-transition:all 0.3s linear;
                    -o-transition:all 0.3s linear;
                    -ms-transition:all 0.3s linear;
                    transition:all 0.3s linear;}

#container1.on      {left:250px} /* It moves if from pos absolute of parent, the body tag in this example */



/* 2D translate */
#container2         {top:120px; background:yellow;
                    -webkit-transition:all 0.3s linear;
                    -moz-transition:all 0.3s linear;
                    -o-transition:all 0.3s linear;
                    -ms-transition:all 0.3s linear;
                    transition:all 0.3s linear;}

#container2.on      {-webkit-transform: translate(230px);
                    -moz-transform: translate(230px);
                    -o-transform: translate(230px);
                    -ms-transform: translate(230px);
                    transform: translate(230px);}  /* It moves if from the starting point, 20px left in this example */



/* 3D - translate */
#container3         {top:220px; background:lime;
                    -webkit-transition:all 0.3s linear;
                    -moz-transition:all 0.3s linear;
                    -o-transition:all 0.3s linear;
                    -ms-transition:all 0.3s linear;
                    transition:all 0.3s linear;}

#container3.on      {-webkit-transform: translate3d(230,0,0);
                    -moz-transform: translate3d(230,0,0);
                    -o-transform: translate3d(230,0,0);
                    -ms-transform: translate3d(230,0,0);
                    transform: translate3d(230,0,0);}  /* It moves if from the starting point, 20px left in this example */



/* jQuery Animate */
#container4         {top:320px; background:orange;}

jQuery

    $('#container1').click(function()
    {
        $(this).toggleClass('on');
    })

    $('#container2').click(function()
    {
        $(this).toggleClass('on');
    })

    $('#container3').click(function()
    {
        $(this).toggleClass('on');
    })

    $('#container4').toggle(function()
    {
        $(this).animate({'left':'250px'});

    }, function()
    {
        $(this).animate({'left':'20px'});
    })

【问题讨论】:

  • 您使用的是哪种浏览器?
  • 桌面 - chrome、safari、IE 7/8/9、FF
  • Android 手机 - Chrome、Native、Opera Mobile、Firefox iPhone 3Gs - 原生 safari

标签: jquery css css-animations translate3d


【解决方案1】:

您缺少长度单位px

在css中使用这个:

#container3.on {
    -webkit-transform: translate3d(230px, 0, 0);
    -moz-transform: translate3d(230px, 0, 0);
    -o-transform: translate3d(230px, 0, 0);
    -ms-transform: translate3d(230px, 0, 0);
    transform: translate3d(230px, 0, 0);
}  /* It moves if from the starting point, 20px left in this example */

这是fiddle

【讨论】:

  • 太棒了,谢谢你,真不敢相信我错过了明显的。
  • translate 3d 在 IE9 中不起作用,翻译只是从开始位置跳到结束位置,即没有动画......有什么想法吗?
  • 不支持 ie9 :caniuse.com/#search=3dtransform 但是,我从未使用过这个,但显然它使用 css (transition)(如果在浏览器中可用),否则使用 jQuery 动画作为后备:@ 987654323@
猜你喜欢
  • 2014-08-09
  • 1970-01-01
  • 2016-12-18
  • 2014-06-05
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 2014-07-18
相关资源
最近更新 更多