2013-05-12 44 views
1
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

<head> 
    <title></title> 
    <style> 
    #a{ 
    position:absolute; 
    top:136px; 
    left:200px; 
    height:100px; 
    width:100px; 
    background:#FF0066; 
    } 

    </style> 
    <script src="scripts/jquery.js"></script> 
    <script> 
    var t; 
    $(function(){ 
    $("#a").click(function(){ 
     $("#a").animate(
    { 
     top:0, 
     left:0, 
     t:100 
    },{ 
     step: function (now){ 
     $(this).css('height',now+'%'); 
     $(this).css('width',now+'%'); 
     },duration:'slow' 
    },'linear',function(){ 
     alert('hi'); 
    }); 
    }) 

    }) 



    </script> 
</head> 

<body> 
<div id="a"></div> 
</body> 

</html 

我想在animate函數完成後創建一個函數。但是因爲我使用的是step,所以當動畫完成時函數沒有被調用。當使用step動畫時可以調用函數嗎?或者當我的動畫完成後,還有什麼其他方式可以調用該函數?在動畫函數之後調用函數與步驟一起使用?

回答

3

您需要傳遞一個函數才能完成。

$(function(){ 
    $("#a").click(function(){ 
    $("#a").animate({ 
     top:0, 
     left:0, 
     t:100 
     }, 
     { 
     step: function (now){ 
      $(this).css('height',now+'%'); 
      $(this).css('width',now+'%'); 
      }, 
      complete: function(){ 
      alert('end ani'); 
      } 

     } 
    ); 
    }); 
}); 
+0

我試過,但它顯示錯誤 「語法錯誤:缺少)後的參數列表 },完整:函數(){」 – 2013-05-12 20:50:49

+0

在這裏展示:http://jsfiddle.net/9vVLc/5/ – mal200 2013-05-12 20:58:46

+0

對不起這是我的錯誤。我沒有刪除持續時間部分。它工作正常。謝謝... – 2013-05-12 21:03:09