gpt4 book ai didi

类型 'offsetWidth' 上不存在 Angular 属性 'Element'

转载 作者:行者123 更新时间:2023-12-04 11:59:00 27 4
gpt4 key购买 nike

Angular 新手,我正在尝试使用 ScrollTrigger 进行水平滚动。
它有效,但是当我提供或构建时,出现错误:
类型“元素”上不存在属性“偏移宽度”。
这是 gsap 的代码:

gsap.to(sections, {
xPercent: -100 * (sections.length - 1),
ease: "none",
scrollTrigger: {
trigger: ".panel-container",
pin: true,
scrub: 1,
snap: 1 / (sections.length - 1),
end: () => "+=" + document.querySelector(".panel-container").offsetWidth
}
});
即使我得到它工作的错误,当我控制台记录“document.query ..”时,我得到了很好的元素宽度。
但是该错误阻止我进行 ng build。
我已经做了 Actor 的事情,首先是:
let myElem = document.querySelector(".panel-container").offsetWidth as HTMLElement;
或者之前,但这不起作用,我有一 strip 有红色下划线的行,并带有错误消息:
将 'string' 类型转换为 'HTMLElement' 类型可能是错误的,因为这两种类型都与另一种类型没有足够的重叠。
我的 Angular 项目是 10.0.5。
在回复中尝试了解决方案:
(document.querySelector(".panel-container") as HTMLElement).offsetWidth;
但是在红色下划线上出现此错误,但在我发球时在控制台中没有。

Conversion of type 'Element' to type 'HTMLElement' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.Type 'Element' is missing the following properties from type 'HTMLElement': accessKey, accessKeyLabel, autocapitalize, dir, and 105 more.ts(2352)

最佳答案

尝试输入来自 querySelector 的预期输出.
那是:

document.querySelector<HTMLElement>(".panel-container").offsetWidth

关于类型 'offsetWidth' 上不存在 Angular 属性 'Element',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63266167/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com