javascript - Jquery settimeout not waiting to redirect -


well, trying set timer on redirect webpage, when use settimeout not work.

    settimeout(function() {         window.location.replace("https://github.com/riggster"");     }, 2000); 

it redirects me, not wait 2 seconds. , not sure why.

$(document).ready(function () {     var gsb = $('.github-side-bar');     var rd = $('.redirectnotice');     gsb.on('click' , function() {         $('html, body').animate({             scrolltop: 0         }, 500);         rd.show('slow');         settimeout(function() {             window.location.replace("https://github.com/riggster"");         }, 2000);     }); 

associated html:

<a href="#top" class="back-to-top"><img src="./asset/img/btt.ico" width="32" height="32" /></a> <a href="https://twitter.com/euanriggans" class="twitter-side-bar"><img src="./asset/img/twitter.ico" width="32" height="32" /></a> <a href="https://github.com/riggster" class="github-side-bar"><img src="./asset/img/github.ico" width="32" height="32" /></a> <div class="redirectnotice"><img src="./asset/img/loading.svg" width="200" height="200" /><h1>redirecting you</h1></div> 

you need prevent default action of anchor

gsb.on('click' , function(e) {      e.preventdefault();      $('html, body').animate({         scrolltop: 0     }, 500);     rd.show('slow');     settimeout(function() {         window.location.replace("https://www.google.com");     }, 2000); }); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -