animate's callback function (complete) executed at start?

后端 未结 8 2070
渐次进展
渐次进展 2020-12-15 03:07

I\'m using jQuery 1.5.1 This is my code:

$(\'.cellcontent\').animate({
   left: \'-=190\'}, {
   easing: alert(\'start ani\'),
   duration: 5000,
   complete         


        
相关标签:
8条回答
  • 2020-12-15 03:49

    Best solution is this.

    $('.cellcontent').animate({
        left: '-=190'}, {
        easing: alert('start ani')
    }, duration).promise().done(function () {
         alert('end animation');
    });
    
    0 讨论(0)
  • 2020-12-15 03:55

    from the jquery docs:

    $( "#clickme" ).click(function() {
      $( "#book" ).animate({
        opacity: 0.25,
       left: "+=50",
        height: "toggle"
      }, 5000, function() {
        // Animation complete.
      });
    });
    
    0 讨论(0)
  • 2020-12-15 03:55

    I dont think you need "complete"?

    slideToggle(
    					"fast","swing", function(){
    							// your code here
    						}
    				);

    0 讨论(0)
  • 2020-12-15 03:57
    $('.cellcontent').animate({
      left: '-=190',
      easing:  'slow',
      duration: 5000,
      function () {
        alert('end ani');
      }
    });
    
    0 讨论(0)
  • 2020-12-15 03:58

    I see two things wrong with this.

    One, easing should be:

    A string indicating which easing function to use for the transition

    And complete should be a function.

    http://api.jquery.com/animate

    alert('start ani');
    $('.cellcontent').animate({
         left: '-=190'
       },
       {
         easing: 'swing',
         duration: 5000,
         complete: function(){
            alert('end ani');
        }
    });
    
    0 讨论(0)
  • 2020-12-15 04:01

    You need to pass a function to call. Instead you are calling the function.

    complete:  function() { alert('end ani'); } 
    
    0 讨论(0)
提交回复
热议问题