如何解决react-full-page阻止我的页面以特定的ID例如http:// localhost:3000 /#someIdWhereIWantThePageToBeOpened打开
我正在使用react-full-page
,并且工作正常,但是有2个问题
- 当我通过点击
<a href='#someId'>Go There</a>
之类的锚点来定位某个ID时,它会继续前进,但滚动后,它将返回到点击前的位置 - 当打开具有
http://localhost:3000/#someIdWhereIWantThePageToBeOpened
之类的ID的页面链接时,即使我已禁用disableScroll.on();
的滚动功能,它仍停留在顶部
任何建议如何解决? 谢谢你
解决方法
const [fullTog,setFullTog] = useState('normal');
let hrefPosition = window
.location
.href
.substring(window.location.href.indexOf("#") + 1,window.location.href.length);
disableScroll.on();
useEffect(() => {
if (document.getElementById(hrefPosition) !== null) {
disableScroll.off();
let ind = 0;
let toDeGoTo = setInterval(function () {
if (ind === 10) {
clearInterval(toDeGoTo);
disableScroll.off();
};
document
.getElementById(hrefPosition)
.scrollIntoView({behavior: 'smooth'});
ind++;
console.log(ind);
},200);
} else {
console.log(document.getElementById(hrefPosition));
setTimeout(function () {
disableScroll.off();
},2000);
}
setTimeout(() => {
setFullTog('full-page');
disableScroll.off();
},2000);
},[])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。