2016-11-29 81 views
1

我正在使用fullPage.js插件逐页滚动。该插件使用哈希URL来完成。在页面刷新时,文档始终在最后一个哈希链接上加载。如何在每次刷新后将文档加载到顶部?我尝试添加以下代码,但没有奏效:每次刷新后在index.html加载页面

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

这是链接到的网页 - 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'); 
       } 
      } 

     }); 

链接的github仓库:https://github.com/rimildeyjsr/St.Anthony-Website

+0

你是否试图定期刷新页面? – xtechkid

+0

我一直没有用过哈希,但问题是,如果你坚持在控制台中,这是否导致页面跳回到顶部? 'window.location.hash ='';' – Taplar

+0

@xtechkid:不,我只是想在每次刷新后在最上面加载页面。这就是全部 –

回答

2

它看起来像这样在你的页面上导致它回到顶部。

window.location.hash = '#Page1'; 

所以,你可以尝试这样做,

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

应该发生的任何一次加载的页面,其中包括令人耳目一新。

1

试试这个

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

让我知道如果你面临任何问题

0
if (location.hash) { 
    setTimeout(function() { 

    window.scrollTo(0, 0); 
    }, 1); 
} 
1

正确的方法是通过使用fullPage.js功能moveTo

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

而是通过改变位置哈希建议的解决方案也将这样做。

相关问题