2014-10-22 93 views
0

下面是我的代碼。它運作良好,但我不知道如何增加持續時間並將其緩解。另外我想添加一個回調函數。如何設置動畫的持續時間和緩動屬性()

$(".pcs").animate({ 
     top:height/2-50, 
     left:width/2-50, 
     width:100, 
     opacity:1, 
    },{step: function(now,fx){ 
      $(".pcs").css('-webkit-transform','rotate(' + now + 'deg)'); 
     }}); 
+2

http://api.jquery.com/animate/。我不確定你需要什麼其他信息。 – 2014-10-22 09:09:37

+0

我嘗試了很多方法,但沒有運氣添加這些屬性的步驟: – Tom 2014-10-22 09:13:03

回答

1

Jquery的動畫功能就像這樣:

element.animate(properties, options); 

你可以這樣做:

$(".pcs").animate({ 
    top:height/2-50, 
    left:width/2-50, 
    width:100, 
    opacity:1},{ 
     duration: 1000,/*A string or number determining how long the animation will run. (1000 = 1 second)*/ 
     easing: "linear",/*A string indicating which easing function to use for the transition.*/ 
     step: function(now,fx){ 
      $(".pcs").css('-webkit-transform','rotate(' + now + 'deg)'); 
     }, 
     complete: function() { 
      // Animation complete. 
     } 
    } 
); 

要了解更多的細節,你可以看看

1

.animate(屬性[,時間] [,緩和] [,完整])

所以你可以使用

  $(".pcs").animate({ 
        top:height/2-50, 
        left:width/2-50, 
        width:100, 
        opacity:1, 
       },{step: function(now,fx){ 
         $(".pcs").css('-webkit-transform','rotate(' + now + 'deg)'); 
        , 
        duration: 200,// or any numeric value 
        easing: 'linear' // or any supported easing effect, for more easing effect you can used jquery ui 
        }}); 

檢查有關jquery ui緩解作用

1
$(".pcs").animate({ 
     top:height/2-50, 
     left:width/2-50, 
     width:100, 
     opacity:1, 
    }, { 
     step:function(now,fx){ 
     $(".pcs").css('-webkit-transform','rotate(' + now + 'deg)'); 
     }, 
     duration: /*int*/, 
     easing: /*string*/, 
     complete: /*function when animation is complete*/ 
    });