SOLVED-How to scroll to anchor when page load?

  1. Im trying to scroll the page to an anchor when the page is loaded, but I don´t know why it is not working?

I have an anchor down the page that Im loading.

And then in my js page I have this.

$$(document).on('page:init', '.page[data-name="diagram"]', function (e) {
var page = e.detail;

$$(page.el).on("click",".sokstatistik", function() {	
   		statistikmanaden = $$(page.el).find('input[name=statistikmanad]').val()

   	mainView.router.navigate("/diagram/?statistikmanad="+statistikmanaden, {ignoreCache: true,reloadCurrent:true,  force:true});



Or how can I scroll-go to an anchor? Thanks!

  1. I also tested to put a link on the page to be able to scroll to an anchor but I can´t get that to work as well?
<a href="#goto" class="sliding-link">Link to div</a>
      lots of text...
<div id="goto">I'm the div</div>

Why isn´t this working?
Thanks again.

Yes thanks shastox I got it working with below. Could you please explain your answer from yesterday about how to reload a comonentUrl page it is caching and not reloading the page no matter what I do.

The below will scroll to any anchor with any id.
<a href="#goto">scroll to div</a><div id="goto">scroll to here</div>

$(document).on('click', 'a', function(event) 
   // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
      // Prevent default anchor click behavior

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
        scrollTop: $(hash).offset().top-50
      }, 800, function(){
        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
    } // End if

this works, but now how do we avoid the anchor jump on load?