[英]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
在尝试访问其top
和left
位置之前可用。
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
中,所以它们不包含top
和left
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.