jQuery scrollTo-plugin 在 Firefox 中不起作用

jQuery scrollTo-plugin not working in Firefox

本文关键字:不起作用 Firefox scrollTo-plugin jQuery      更新时间:2023-09-26

今天又来了一个,

所以我昨天实现了jQuery scrollTo插件,在Chrome,Internet Explorer中一切正常,但在Firefox中则不然。控制台日志记录已启用 - 不显示任何错误。似乎滚动功能确实执行了,但我没有看到任何滚动发生。

在OpenSUSE 12.3下的Firefox 28.0和Windows 8.0下的Firefox 34.0上进行了测试。

这是我到目前为止的代码:.HTML

$(document).ready(function() {
    $('a.navLink').on('click', function(event) {
        event.preventDefault();
        var target = $(this).attr('href');
        if( target.length ) {
            if( $("html, body").scrollTo(target, { offset: -128, duration: 750, easing: "easeOutCirc" }) ) {
                console.log("scrolling...");
            } else {
                console.log("I had ONE job...");
            }
        }
    });
});

.HTML:

<nav id="nav">
    <ul>
        <li>
            <a class="navLink" href="#home">HOME</a>
        </li>
        <li>
            <a class="navLink" href="#info">INFO</a>
        </li>
        <li>
            <a class="navLink" href="#pics">PICS</a>
        </li>
    </ul>   
</nav>
<section id="home">
    <!-- stuff -->
</section>
<section id="info">
    <!-- stuff -->
</section>
<section id="pics">
    <!-- stuff -->
</section>

我在这里看到了一个类似的问题(找不到 URL atm),其中发现广告拦截器/安全插件/插件导致 OP 出现此问题。我的测试浏览器中没有安装这样的附加组件/插件。

任何帮助,不胜感激。

试试这个:

$(document).ready(function() {
    $('a.navLink').on('click', function(event) {
        event.preventDefault();
        var target = $(this).attr('href');
        if( target.length > 0 ) {
            $("html, body").animate({
                scrollTop: $(target).offset().top - 128
            }, 750);
        }
    });
});