开发者

the anchor in javascript does not work correctly

Playback Steps:

In the header, click on any of the links with anchors: ##bankaccount #pack #platform #acq ##scorecard ##intrade #form Scroll the page to the top Reload the page Actual result:

When reloading a page with an anchor in the url, there is no scrolling to the block.

Expected result:

When a page with an anchor in the url is reloaded, a scroll to the block occurs.

The problem is that while the page is not fully loaded, the scroll works, but when the page is fully loaded, the scroll goes back up

import React from 'react';

const useScrollToLocation = () => {
    React.useEffect(() => {
       开发者_C百科 const hash = window.location.hash;
        const id = hash.replace('#', '');
        const element = document.getElementById(id);
        window.location.hash = '';
        if (element) {
            window.location.hash = id;
        }
    }, []);
};
export default useScrollToLocation;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜