What I’m trying to do: Delay my script from appending a particular hash to the URL.
Why I’m doing this: I have a jQuery animation that is (and must) fire before the appending of the URL.
I’ve read about setTimeout, but I have been unable to get it to work. I was thinking that I could delay after the animation occurs, but I didn’t see much documentation on this route. Instead, I’m trying to take the common route of delaying the next line of code in the script, which happens to be the URL-append code. For good measure, I’ve put the animation and the appending code below.
function animate() {
$(".class").animate({height: "100%"},
$(".class").addClass("open");
}
animate(); // animate the bar up.
//append the url with the comment number and a hash.
var new_hash ="#"+split_comment_number;
var delay = setTimeout(function() {window.location.hash = new_hash;},1500);
The easiest approach would be to just use the callback of
animate. It will fire once the animation completes: