Anchor Tag in chrome not working properly?Is this a chrome Bug?

旧城冷巷雨未停 提交于 2019-12-23 15:49:30

问题


I have a site http://rethinkwaste.com.au/ . When clicking on the very first slide I have a anchor set up

<div id="illegal"></div>

On the first load out in google chrome this seems to jump back up to the top of the page. Is this a chrome bug?

If I then refresh or load page from slider link it seems to work ok.


回答1:


I think its a Chrome bug. So After some searching i found this solution.

jQuery(window).load(function(){
    var hashNum = 0;
    if (window.location.hash != ''){
        hashNum = window.location.hash.replace("#illegal", "");   
        console.log('hashNum: ' + hashNum); 
    };
    hashMenu = jQuery("#illegal").offset().top;
      jQuery('html,body').animate({
          scrollTop: hashMenu
    }, 1000);

});



回答2:


Issue might be due to duplicate id #illegal, from your website code I can see this id used twice. Remove unwanted or use unique id and try. It should work



来源:https://stackoverflow.com/questions/37606128/anchor-tag-in-chrome-not-working-properlyis-this-a-chrome-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!