草庐IT

anchorName

全部标签

javascript - 如何将 HTML 页面滚动到给定的 anchor

我想让浏览器将页面滚动到给定的anchor,只需使用JavaScript。我在我的HTML代码中指定了name或id属性:..或..我希望通过导航到http://server.com/path#anchorName来获得与您相同的效果。应滚动页面,使anchor靠近页面可见部分的顶部。 最佳答案 functionscrollTo(hash){location.hash="#"+hash;}根本不需要jQuery! 关于javascript-如何将HTML页面滚动到给定的anchor,我们

javascript - 如何将 HTML 页面滚动到给定的 anchor

我想让浏览器将页面滚动到给定的anchor,只需使用JavaScript。我在我的HTML代码中指定了name或id属性:..或..我希望通过导航到http://server.com/path#anchorName来获得与您相同的效果。应滚动页面,使anchor靠近页面可见部分的顶部。 最佳答案 functionscrollTo(hash){location.hash="#"+hash;}根本不需要jQuery! 关于javascript-如何将HTML页面滚动到给定的anchor,我们