jquery - CSS3 动画 Translate3d 不工作

标签 jquery css css-animations translate3d

我一直在尝试 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'});
    })

最佳答案

您缺少长度单位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

关于jquery - CSS3 动画 Translate3d 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13361449/

相关文章:

javascript - 如何在 JS 函数中正确创建按钮监听器

html - 将文本设置在同一行

javascript - Jquery 鼠标单击事件不适用于某些功能

html - 如何为选择标签添加边框

hover - 添加一个 :hover box-shadow to a picture link

css - 在某些情况下,div 的宽度会增加,即使我有溢出 :auto

css - 提高 CSS3 背景位置动画的性能

html - 我的 CSS 动画在 iOS 中不工作

javascript - Ajax:提交带有表单名称的表单

javascript - 当输入字段为空时,jQuery 验证不起作用