反应延迟滚动onClick

时间:2019-05-07 14:07:47

标签: javascript reactjs

我有以下代码:

...
    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);
                }
            });
        });
    }
...

当我单击一个按钮时,滚动事件中的代码也会运行。有没有办法禁用/延迟“滚动”事件?

0 个答案:

没有答案