我的jQuery脚本在Mozzila中不起作用

时间:2017-02-19 11:55:09

标签: javascript jquery

我尝试了一些jquery来将页面滚动到各个部分。它适用于谷歌浏览器,但在Mozilla Firefox中没有任何反应。

这是我在html中的代码:

<!DOCTYPE html>
<html>

<head>
    <title>LP Portfolio</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Archivo+Narrow|Lobster+Two|Lora|Vollkorn" rel="stylesheet">
    <link rel="stylesheet" href="css/style.css" type="text/css">
</head>

<body>
    <div id="container">
        <div class="hero">
            <div id="header">
                <div id="header-logo">
                    <img src="images/logo.png" alt="header-logo">
                </div>
                <div id="header-opis">
                    <h2><span class="prvo-slovo">L</span>uka <span class="prvo-slovo">P</span>aradzik</h2>
                    <h3>Web Developer</h3>
                </div>

                    <nav>
                        <ul>
                            <li><a href="index.html">Home</a></li>
                            <li><a id="about" href="#aboutSection">About</a></li>
                            <li><a id="portfolio" href="#portfolioSection">Portfolio</a></li>
                            <li><a id="gallery" href="#gallerySection">Gallery</a></li>
                            <li><a id="blog" href="#blogSection">Blog</a></li>
                            <li><a id="contact" href="#contactSection">Contact</a></li>
                        </ul>
                    </nav>

                <div id="header-menu-gumb">
                    <a href="#"><img src="images/menu.png"></a>
                </div>
            </div>
        </div>

        <div id="aboutSection">

我有5个带有id的div,在导航标签中是href。 在我的html文档的末尾,我将html与js脚本链接在一起:

    <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="js/scrolling.js"></script>

这是scrolling.js脚本中的代码:

$(document).ready(function() {
    skrolanjeStranice();
});

function skrolanjeStranice() {

    $("nav a").click(function(e) {

        e.preventDefault();

        var sectionID = e.currentTarget.id + "Section";


        $("html body").animate({

            scrollTop: $("#" + sectionID).offset().top

        }, 1000)
    })
}

在Mozilla浏览器控制台中,我收到此错误:

TypeError: $(...).offset(...) is undefined  scrolling.js:19:15

在Google Chrome中,一切都很完美。

感谢您的帮助。也很抱歉问题的解释不好。 我是新手,我只是想学习新东西。

0 个答案:

没有答案