call back for javascript animation -


i have java script animation scrolling unto top of page smoothly.at end of animation have .focus() function focus on form field. focus causing jerkiness. upon researching found out can fix having call animation , having focus in that. not sure how that. appreciated.

  $(".scroll").click(function(event){      event.preventdefault();      //calculate destination place      var dest=0;      if($(this.hash).offset().top > $(document).height()-$(window).height()){           dest=$(document).height()-$(window).height();      }else{           dest=$(this.hash).offset().top;      }      //go destination      $('html,body').animate({scrolltop:dest}, 1000,'swing');       $('input#name_first').focus();  }); 

http://jsfiddle.net/1kbph7q3/

both comments on question correct.

heres working js fiddle: http://jsfiddle.net/got29e9v/1/

  1. the first error anchor link need class of .scroll.
  2. also js fiddle wasn't using jquery, javascript trying use it.
  3. i've added callback function on animate method. called when animation completes.

hope helps.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -