title: Restore scroll position after mobile menu is closed
body: <p>I'm having a mobile menu that opens and closes using jquery by adding a css class that has display:block while the menu div has display:none.
  The jquery code has a part where it is supposed to close the menu when a click is registered outside the menu div. Everything works execept the: <code>$("body").scrollTop(scrollpos)</code> . This was supposed to scroll the user back where he left off after the <code>scrollTop(0)</code> took place and the menu has closed, but it does not scroll at all the scroll is stuck at the top. Any help will be appreciated. Thank you.</p>
  
  <p>EDIT: Here is an example: <a href="https://jsfiddle.net/mufwwudj/" rel="nofollow">https://jsfiddle.net/mufwwudj/</a></p>
  
  <pre><code>$(function () {
      var menutoggle = $(".menu-toggle");
      var sidenav = $(".side-nav");
  
      menutoggle.click(function () {
          var scrollpos = $('body').scrollTop();
          if (!$("body").hasClass("m-nav-open")) {
              $("body").scrollTop(0).addClass("m-nav-open");
          }
          $(document).mouseup(function (e){
          if (!sidenav.is(e.target) &amp;&amp; sidenav.has(e.target).length === 0 &amp;&amp; !menutoggle.is(e.target) &amp;&amp; menutoggle.has(e.target).length === 0){
                  if ($("body").hasClass("m-nav-open")) {
                      $("body").scrollTop(scrollpos).removeClass("m-nav-open");
                  }
          }
          });
      });
  });
  </code></pre>