2013-09-27 31 views
1

我想使用jQuery的動畫轉換爲時鐘。但它不工作.. 我寫這樣的代碼:與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

回答

6

你的參數順序弄亂了,希望你正在尋找的是

$(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