简体   繁体   English

链接到不同页面中的部分不起作用

[英]Link to a section in a different page not working

I am trying to create a link to a different section of another webpage in HTML by using the following code.我正在尝试使用以下代码在 HTML 中创建指向另一个网页不同部分的链接。 The link below in the tourPack.html page tourPack.html页面中的以下链接

<li><a href="/html/index.html#section2">Gallery</a></li>

The code of section 2 given below is in index.html page下面给出的第 2 节的代码在index.html页面中

<div class="section" id="section2">
   <a name="1"></a>
   <div class="aboutMeContainer">
      <div class="introduction" data-aos="fade-up" data-aos-duration="800">
         <h2 data-aos="fade-up" data-aos-duration="1200">Explore Sri Lanka with Monkey Tours</h2>
         <p data-aos="fade-up" data-aos-duration="1000">Lorem, ipsum dolor sit amet consectetur
            adipisicing elit. Eius nostrum consectetur veritatis
            porro,
            modi
            nobis, deleniti voluptatem vitae
            repudiandae excepturi natus ex qui possimus eaque animi minus cum corrupti aliquam esse
            recusandae
            adipisci sit, sint dignissimos rem. Impedit, sequi tenetur.
         </p>
         <div class="CEOImageContainer">
            <img src="/images/AkilaPunchihewa.jpg" alt="Founder">
         </div>
         <hr>
         <span class="title">Founder</br>Akila Punchihewa</span>
      </div>
   </div>
</div>

It gets redirected to the index.html page but not to the section2.它被重定向到index.html页面,但不会重定向到 section2。 I also use a bunch of javascript in index.html including the full page scrolling library fullPage.js .我还在 index.html 中使用了一堆 javascript ,包括整页滚动库fullPage.js The link seems to be working correctly when I disable Javascript altogether.当我完全禁用 Javascript 时,该链接似乎工作正常。 Any help is appreciated :)任何帮助表示赞赏:)

EDIT:编辑:

I tried this little workaround我试过这个小解决方法

<script>
    $(document).ready(function () {
        alert(window.location.hash);
        if (window.location.hash) {
            setTimeout(function () {
                $('html, body').animate({
                        scrollTop: $('#section2').offset().top
                    },
                    1000);
            }, 1000);
        }
    });
</script>

It works as long as the fullPage.js CDN is disabled.只要fullPage.js CDN被禁用,它就可以工作。

Here is my fullPage script这是我的 fullPage 脚本

 <script>
        $(document).ready(function () {
            $('#fullPageContainer').fullpage({
                autoScrolling: true,
                navigation: true,
                scrollBar: true,
                navigationTooltips: ['Monkey Tours', 'About us', 'Gallery', 'Reviews', 'Tour Packages',
                    'Contact Us'
                ],
                responsiveWidth: 769,
                responsiveHeight: 0,
                keyboardScrolling: true,
                controlArrows: false,
                slidesNavigation: true,
                loopBottom: true,
                css3: true,
                loopBottom: true,
                afterRender: function () {
                    setInterval(function () {
                        $.fn.fullpage.moveSlideRight();
                    }, 100000000);
                }
            });
            fullpage_api.setMouseWheelScrolling(false);
        });
 </script>

You are not using the fullPage.js option named anchors .您没有使用名为anchors的 fullPage.js 选项。 That's the option you need to use in order to get the anchor for each section.这是您需要使用的选项,以便为每个部分获取锚点。

You can read more about it in the the fullpage.js documentation and you can see plenty of examples on theexamples folder .您可以在 fullpage.js 文档中阅读有关它的更多信息,并且您可以在examples 文件夹中看到大量示例

For example:例如:

  new fullpage('#fullpage', {
    anchors:['section1', 'section2', 'section3']
  });

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

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