Why do page anchors sometimes miss?

后端 未结 7 1562
灰色年华
灰色年华 2020-12-15 05:41

On an HTML page, a link like this:

Location on Page

...should navigate to this spot on the

7条回答
  •  [愿得一人]
    2020-12-15 06:21

    JS Solution

    Run this function on document ready.

     function goToAnchor() { 
        hash = document.location.hash;
        if (hash !="") {
            setTimeout(function() {
                if (location.hash) {
                    window.scrollTo(0, 0);
                    window.location.href = hash;
                }
            }, 1);
        }
        else {
            return false;
        }
    }
    

提交回复
热议问题