美文网首页
React锚点滚动

React锚点滚动

作者: 以德扶人 | 来源:发表于2019-01-06 16:45 被阅读28次

1.加入这个跳转方法

 //描点跳转
    scrollToAnchor = (anchorName) => {
        if (anchorName) {
            // 找到锚点
            let anchorElement = document.getElementById(anchorName);
            // 如果对应id的锚点存在,就跳转到锚点
            if(anchorElement) { anchorElement.scrollIntoView({block: 'start', behavior: 'smooth'}); }
        }
    }

2.在要跳的div标记id:'xxx'.
3.在对应的按钮上面执行点击方法

相关文章

网友评论

      本文标题:React锚点滚动

      本文链接:https://www.haomeiwen.com/subject/mnbsrqtx.html