1

I am using the fullPage.js plugin to scroll page by page. The plugin is using hash urls to do so. On page refresh, the document is always loading on the last hash url it was on. How to make the document load at the top after every refresh? I tried adding the following code but it did not work out:

$(document).ready(function(){
   $(document).scrollTop(0);
});

This is the link to the webpage - https://rimildeyjsr.github.io/St.Anthony-Website

jQuery :

 $('#fullpage #section1').hide();
 $(document).ready(function(){
        $('#fullpage #section1').show();
        $('#fullpage').fullpage({
            anchors:['Page1','Page2','lastpage'],
            afterLoad : function(anchorLink,index) {
                if (index == 2 || anchorLink == 'Page2'){
                    $('.school-name').addClass('animated slideInUp').css('visibility','visible');
                }
            }

        });

Link to github repository : https://github.com/rimildeyjsr/St.Anthony-Website

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
Rimil Dey
  • 827
  • 2
  • 13
  • 33
  • are you trying to refresh the page periodically ? – Sudheej Nov 29 '16 at 04:33
  • I have not worked with hashes much, but question, if you stick this in the console, does it cause the page to jump back up to the top? `window.location.hash = '';` – Taplar Nov 29 '16 at 04:34
  • @xtechkid : No. I just want to load the page on the very top after every refresh. That's all – Rimil Dey Nov 29 '16 at 04:40
  • Take a look here, this question is already asked before: http://stackoverflow.com/a/3659116/3058905 – BlitZz Nov 29 '16 at 04:41

4 Answers4

2

It looks like this on your page causes it to go back to the top.

window.location.hash = '#Page1';

So you could try doing that

$(window).on('load', function() {
    window.location.hash = '#Page1';
});

which should happen any time you load the page, including refreshing.

Taplar
  • 24,788
  • 4
  • 22
  • 35
1

Try This

 if(location.href.split('#').length > 0){
    location.href = location.href.split('#')[0]
 }

Let me know if you face any issue

Deepak
  • 1,373
  • 2
  • 10
  • 31
1

The proper way would be by using the fullPage.js function moveTo:

$(window).on('load', function() {
    $.fn.fullpage.moveTo(1);
});

But the suggested solution by changing the location hash will also do it.

Alvaro
  • 40,778
  • 30
  • 164
  • 336
0
if (location.hash) {
  setTimeout(function() {

    window.scrollTo(0, 0);
  }, 1);
}
BlitZz
  • 132
  • 1
  • 14