简体   繁体   English

控制台错误无法解构 'el.position(...)' 的属性 'top',因为它未定义。 wordpress jquery

[英]console error Cannot destructure property 'top' of 'el.position(…)' as it is undefined. wordpress jquery

So I am working on a wordpress site I am not familiar with.所以我在一个我不熟悉的 wordpress 网站上工作。 I get the following error in the console:我在控制台中收到以下错误:

jquery-3.5.1.min.js:formatted:1504 Uncaught TypeError: Cannot destructure property 'top' of 'el.position(...)' as it is undefined.
    at doDotsCalculations (main.js?ver=20190317:6)
    at setOwlDotsPosition (main.js?ver=20190317:5)
    at HTMLDocument.<anonymous> (main.js?ver=20190317:5)
    at e (jquery-3.5.1.min.js:formatted:1422)
    at t (jquery-3.5.1.min.js:formatted:1433)

I am not entirely sure but this is what i got in main.js and where the error originated from.我不完全确定,但这就是我在 main.js 中得到的以及错误的来源。 Any help is much appriciated.任何帮助都非常受欢迎。 I cant see any visual errors in the site but it is adapted for screenreaders and other stuff i cant check for.我在网站上看不到任何视觉错误,但它适用于屏幕阅读器和其他我无法检查的东西。

    $(function() {
        if ($.fn.multiscroll !== undefined) {
            $('#multiscroll').multiscroll({
                verticalCentered: true,
                anchors: ['first', 'second', 'third', 'fourth', 'fifth'],
                menu: '#msmenu',
                navigation: false,
                css3: true,
                navigationTooltips: ['First', 'Two', 'Three'],
                responsiveWidth: 992,
                responsiveExpand: true,
                loopBottom: false,
                loopTop: false,
                onLeave: function(index, nextIndex, direction) {},
                afterLoad: function(anchorLink, index) {},
                afterRender: function() {}
            });
        }
        if ($.fn.fullpage !== undefined) {
            $('#fullpage').fullpage({
                sectionsColor: [],
                anchors: ['firstPage', 'secondPage', '3rdPage'],
                menu: '#fpsmenu',
                responsiveExpand: true,
                responsiveWidth: 1400,
                continuousVertical: true,
                navigation: false,
                verticalCentered: false
            });
            $.fn.fullpage.setAllowScrolling(true);
        }
        $(".owl-carousel").on("initialized.owl.carousel", ()=>{
            setTimeout(()=>{
                $(".owl-item.active .owl-slide-animated").addClass("is-transitioned");
                $("section").show();
            }
            , 200);
        }
        );
        const $owlCarousel = $(".owl-carousel").owlCarousel({
            items: 1,
            loop: true,
            nav: true,
            navText: ['<svg width="32" height="32" viewBox="0 0 24 24"><path d="M16.67 0l2.83 2.829-9.339 9.175 9.339 9.167-2.83 2.829-12.17-11.996z"/></svg>', '<svg width="32" height="32" viewBox="0 0 24 24"><path d="M5 3l3.057-3 11.943 12-11.943 12-3.057-3 9-9z"/></svg>']
        });
        $owlCarousel.on("changed.owl.carousel", e=>{
            $(".owl-slide-animated").removeClass("is-transitioned");
            const $currentOwlItem = $(".owl-item").eq(e.item.index);
            $currentOwlItem.find(".owl-slide-animated").addClass("is-transitioned");
            const $target = $currentOwlItem.find(".owl-slide-text");
            doDotsCalculations($target);
        }
        );
        $owlCarousel.on("resize.owl.carousel", ()=>{
            setTimeout(()=>{
                setOwlDotsPosition();
            }
            , 50);
        }
        );
        setOwlDotsPosition();
        function setOwlDotsPosition() {
            const $target = $(".owl-item.active .owl-slide-text");
            doDotsCalculations($target);
        }
        function doDotsCalculations(el) {
            const height = el.height();
            const {top, left} = el.position();
            const res = height + top + 20;
            $(".owl-carousel .owl-dots").css({
                top: `${res}px`,
                left: `${left}px`
            });
        }
        $(".carousel .carousel-item").first().addClass("active");
    });

You encountered this error because the element or some of its properties are undefined .您遇到此错误是因为element或其某些属性undefined Add a check to ensure that el is available before trying to access its top and left positions.添加检查以确保el在尝试访问其topleft位置之前可用。

function doDotsCalculations(el) {
  if (el) {
    const height = el.height();
    const {top, left} = el.position();
    const res = height + top + 20;
    $(".owl-carousel .owl-dots").css({
      top: `${res}px`,
      eft: `${left}px`
    });
  }
  return null;
}

UPDATE : Remove the code from pages that are not using the Carousell to eliminate the error that you are facing.更新:从不使用 Carousell 的页面中删除代码以消除您面临的error Pages that are not using it will most certainly not be able to locate the css classes .owl-item.active.owl-slide-text" , which do not contain top and left values since the css classes are not in the DOM .不使用它的页面肯定无法找到css.owl-item.active.owl-slide-text" ,因为css类不在DOM中,所以它们不包含topleft值。

暂无
暂无

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

相关问题 无法解构属性,因为它未定义。 使用上下文错误 - Cannot destructure property as it is undefined. useContext error 无法解构“未定义”的属性“历史”,因为它未定义。 --React.js - Cannot destructure property 'history' of 'undefined' as it is undefined. --React.js TypeError:无法解构“pres [0]”的属性“标题”,因为它未定义。 (反应) - TypeError: Cannot destructure property 'title' of 'pres[0]' as it is undefined. (REACT) 错误:未捕获 [TypeError:无法解构“props.value”的属性“匹配”,因为它未定义。] - Error: Uncaught [TypeError: Cannot destructure property 'match' of 'props.value' as it is undefined.] TypeError:无法解构“未定义”的属性“位置”,因为它未定义 - TypeError: Cannot destructure property 'position' of 'undefined' as it is undefined jQuery 控制台错误:无法读取未定义的属性“top” - jQuery Console Error: Cannot read property 'top' of undefined 无法解构属性,因为它是未定义的 - Cannot destructure property as it is undefined NEXTJS - 无法解构“req.body”的属性“名称”,因为它未定义。 (补丁方法) - NEXTJS - Cannot destructure property 'name' of 'req.body' as it is undefined. (PATCH Method) TypeError:无法解构“对象(…)(…)”的属性“setValues”,因为它未定义。 (反应/创建反应应用) - TypeError: Cannot destructure property 'setValues' of 'Object(…)(…)' as it is undefined. (react / create-react-app) 无法读取未定义的属性“textContent”。 控制台显示错误,但代码仍然有效? - Cannot Read property “textContent” of undefined. Console showing an error, but code still works?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM