在 Easy Dots Scroll 库上获取“未捕获的类型错误:无法读取未定义的属性‘顶部’”?

时间:2021-03-07 20:14:43

标签: javascript html jquery css scroll

我正在使用由开发人员创建的 Easy Dots Scroll 库,该库是我从 github 在网站项目上下载的,三个滚动点出现在侧面,但是当我单击其中任何一个以跳转到网站上的部分时由点表示它不起作用,在控制台中我收到错误 script2.js:184 Uncaught TypeError: Cannot read property 'top' of undefined

检查控制台中的代码这是包含错误的代码部分

`

function scrollIndiClicked(indiId) {
   

     if (window.jQuery) {
            // if jquery is availble then we can use jquery animations
            if (dotFixedNavPresent === true && dotFixedNavId.length) {
                // there is a fixed nav and its id has been defined
                const dotNavHeightElem = document.getElementById(dotFixedNavId);
                const dotNavHeight = dotNavHeightElem.clientHeight;
                const dotDocumentHtml = $('html, body');
                const indiElement = $('#' + indiId);
        
                if (dotFixedNavUp === true) {
                    // fix nav on upward scroll only
                    dotDocumentHtml.animate({
                        scrollTop: indiElement.offset().top
                    }, 700);
                    const scrollPos = document.body.getBoundingClientRect().top;
                    setTimeout(function () {
                        if (document.body.getBoundingClientRect().top > scrollPos) {
                            dotDocumentHtml.animate({
                                scrollTop: indiElement.offset().top - dotNavHeight
                            }, 400);
                        }
                    }, 400);
                }
                else {
                    // fixed nav scroll
                    dotDocumentHtml.animate({
                        scrollTop: indiElement.offset().top - dotNavHeight
                    }, 700);
                }
            }
            else {
                // normal scroll
                $('html, body').animate({
                    scrollTop: $('#' + indiId).offset().top
                }, 700);
            }    
        }
        else {

`

更具体地说,错误来自此处的 top 属性

` // 正常滚动

  $('html, body').animate({
            scrollTop: $('#' + indiId).offset().top
        }, 700);

`

谁能帮帮我?提前致谢。

0 个答案:

没有答案