Reputation: 117
I am trying to make use of jQuery to scroll down to a text box on the click event. But the scroll event takes place after the ajax call in the function happens.
$("#execute_btn").click(function(){
$('html, body').animate({
scrollTop: $("#scripts_execution_section").offset().top
}, 500);
// Ajax Synchronous call
});
So It will execute the Ajax call, and only after the response it will scroll down. How can I make it such that it will scroll down and then make the ajax call?
Thank you,
Upvotes: 0
Views: 54
Reputation: 12717
In your jQuery.animate(), add last parameter callback function to be called only after the animation is done
$('html, body').animate({
scrollTop: $("#scripts_execution_section").offset().top
}, 500,function(){
// your ajax call here
});
Upvotes: 2