我有以下代码:
...
componentDidMount() {
const {fieldGroups, setNavigationSections, setNavigationSectionActive} = this.props;
const filteredFieldGroups =
fieldGroups
.filter(fieldGroup => fieldGroup.title)
.map(fieldGroup => ({
id: fieldGroup.key,
title: fieldGroup.title
}));
if (setNavigationSections) {
setNavigationSections(filteredFieldGroups);
}
document.addEventListener('scroll', () => {
sections.forEach(section => {
if (document.getElementById(section).getBoundingClientRect().top <= 0) {
setNavigationSectionActive(section);
}
});
});
}
...
当我单击一个按钮时,滚动事件中的代码也会运行。有没有办法禁用/延迟“滚动”事件?