【问题标题】:Transform with jQuery is not working使用 jQuery 进行转换不起作用
【发布时间】:2013-09-27 09:58:06
【问题描述】:

我正在尝试使用 jQuery 对时钟进行动画转换。但它不工作.. 我写了这样的代码:

var now = new Date();
var hr = now.getHours();
var min = now.getMinutes();
var sec = now.getSeconds();
hr = hr % 12;
hr = hr * 30;
$('#hour').animate({
    step: function (hr) {
        $(this).css('-webkit-transform', 'rotate(' + hr + 'deg)');
    },
    duration: 10
}, 'linear');

更多信息请查看我的JSFiddle

【问题讨论】:

    标签: jquery animation transform


    【解决方案1】:

    您的参数顺序搞砸了,希望您正在寻找的是

    $(document).ready(function () {
        var now = new Date();
        var hr = now.getHours();
        var min = now.getMinutes();
        var sec = now.getSeconds();
        hr = hr % 12;
        hr = hr * 30;
        $('#hour').animate({
            transform: hr
        }, {
            step: function (hr) {
                $(this).css('-webkit-transform', 'rotate(' + hr + 'deg)');
            },
            duration: 1000
        }, 'linear');
    });
    

    演示:Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2022-01-21
      相关资源
      最近更新 更多