javascript - Jquery - animate after redirection -


i animate page after page redirected using jquery, problem code redirects ignores animation code, how can resolve issue ?

  $("#menu a:first-child").click(function() {       window.location.href = "https://www.mysite/blog";       $('html,body').animate({           scrolltop: $("#mainwrapper").offset().top - 70},           'slow');   }); 

(the animation scrolls down anchor fluid transition.)

when redirect, current script stop. if 1 it, think there way, not recommend it, job. before redirect other page; assume new page still in same app, not totally different website), can set localstorage variable. @ beginning of js file of page redirect to, check if localstorage variable have set in earlier view there, if is, animation, remove localstorage variable.

  // js file of current view   $("#menu a:first-child").click(function() {     localstorage.setitem("animation", true)     window.location.href = "https://www.mysite/blog";   });    // js file of redirected view   if (localstorage.animation && json.parse(localstorage.animation)) {     $('html,body').animate({       scrolltop: $("#mainwrapper").offset().top - 70},       'slow', 'linear', function() {          localstorage.removeitem("animation")       }     );   } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -