【问题标题】:After clicked URL to another page and scroll单击 URL 到另一个页面并滚动后
【发布时间】:2018-01-09 05:04:04
【问题描述】:

我有一个页面网站和几个通用页面。当用户单击将用户从通用页面重定向到主页的链接时,我不确定如何实现解决方案。用户进入主页后,我希望它自动向下滚动到调用 id="contactForm">

的部分

我怎样才能做到这一点?

【问题讨论】:

  • 能否请您添加您尝试过的内容

标签: javascript php wordpress templates


【解决方案1】:

href<a>标签中,这样写"link-to-homepage#contactForm"

【讨论】:

    【解决方案2】:

    HTML

    <nav class="header-menu">
        <ul>
            <li><a href="#aboutus">Company</a></li>
            <li><a href="#services">Services</a></li>
            <li><a href="#careers">Careers</a></li>
            <li><a href="#contactus">Contact</a></li>
        </ul>
    </nav>      
    <section id="aboutus">
        content here
    </section>
    <section id="services">
        content here
    </section>
    <section id="careers">
        content here
    </section>
    <section id="contactus">
        content here
    </section>
    

    JS

    jQuery(".header-menu a").click(function(e) {
        var speed = 2000;
        var position = jQuery(jQuery(this).attr("href")).offset().top;
        jQuery('html, body').animate({
            scrollTop: position
        }, speed, "linear");
       return false;
    });
    

    【讨论】:

      【解决方案3】:

      在链接中,您需要放置部分(主页)的 id。喜欢

      <a href="index.php#section-id">Click</a>
      

      如果您将上述代码放在站点的任何位置,它会将您重定向到 index.php 并滚动到给出 id 的部分。

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2021-11-13
        • 1970-01-01
        • 2018-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-07
        相关资源
        最近更新 更多