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(); });
both comments on question correct.
heres working js fiddle: http://jsfiddle.net/got29e9v/1/
- the first error anchor link need class of
.scroll
. - also js fiddle wasn't using jquery, javascript trying use it.
- i've added callback function on animate method. called when animation completes.
hope helps.
Comments
Post a Comment