Ari*_*nna 11 javascript typescript angular
在 angular8 环境中的编译过程中,我在终端中收到此错误。在本地主机上,我导航页面没有任何问题,控制台中也没有任何错误。我创建了一个已分配该数据集属性的变量的 console.log,并且它被正确读取。下面是感兴趣的代码部分:
let timelineEls = document.querySelectorAll('[data-scroll-timeline]');
scroll.on("scroll", () => {
for ( let i = 0; i < timelineEls.length; i++ ) {
let progress = self.getProgress(timelineEls[i]);
let timelineKey = timelineEls[i].dataset.scrollTimeline;
console.log(timelineEls[i].dataset);
let timeline = timelines[timelineKey]._recent;
let timeline = timelines[timelineKey];
let duration = timeline.duration();
if ( progress > 0 && progress <= 1 ) {
timeline.seek(progress * duration);
} else {
if ( progress <= 0 ) {
timelines[timelineKey].seek(0);
} else {
timelines[timelineKey].seek(duration);
}
}
}
})
Run Code Online (Sandbox Code Playgroud)
console.log 正确标记:DOMStringMap {scroll: "", scrollTimeline: "albed-anim"}
你知道如何摆脱这个错误吗?我想这是一个打字稿错误,但在它显示时我找不到任何原因以及如何避免它。
先感谢您。
Pie*_*Duc 15
该属性dataset在 type 上不存在Element,但在 上存在HTMLElement。在继续之前,您需要确保它是这种类型。它还可以稍微调整您的 for 循环:
for (const timelineEl of timelineEls) {
if (timelineEl instanceof HTMLElement) {
const progress = self.getProgress(timelineEl);
const timelineKey = timelineEl.dataset.scrollTimeline;
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5531 次 |
| 最近记录: |