简体   繁体   English

如何滚动在首页上的锚点之间放置另一个页面(例如:关于)

[英]How to scrollTop an anchor in home page by another page (eg.: about)

Has anyone had this problem before? 有人遇到过这个问题吗? I am on an internal page (like about.html) and I want to scrollTop to an anchor in home page (like home.html#sectionID), but I don't know how can I do that with jQuery.. I've already tried some stuffs but it doesn't work. 我在内部页面上(如about.html),并且我想scrollTop到主页上的锚点(如home.html#sectionID),但我不知道如何使用jQuery。已经尝试了一些东西,但是没有用。 Here is my actual code that works if I am in the home page.. 如果我在主页中,这是我的实际代码。

  $(".anchor-link").click(function(e) {
    e.preventDefault();
    $('html, body').animate({
        scrollTop: $( $(this).attr('href') ).offset().top + (-117)
    }, 1000);
    return false;
  });

Instead of using $(this).attr('href') , use any selector in the top of page where you want to scroll. 不要使用$(this).attr('href') ,而要使用页面顶部要滚动的任何选择器。 If you have #home id in top then you need to use: 如果您在顶部有#home id,则需要使用:

$('html, body').animate({
    scrollTop: $('#home').offset().top + (-117)
}, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM