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

I want a function after the animate function is complete.But since I am using step the function is not getting called when the animation is complete.Is it possible to call function when animate with step is used? Or is there any other way by which I could call the function when my animation is complete?

4

1 回答 1

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');
          }

      }
      );
  });
});
于 2013-05-12T20:47:07.427 回答