div scroll to in javascript

眉间皱痕 提交于 2019-12-11 08:42:14

问题


I have several divs with content. Some of the context is wrapped with,

content <a name='SomeName'> cool content </a> more content

In Javascript how do I force the SomeName name to scroll into view for that DIV only. The catch is that there are many DIVs on the page with content.

I have the Div's object known. The Div can contain other divs etc in a hierarchy. Somewhere in there is the SomeName anchor.

site: http://BiblePro.BibleOcean.com


回答1:


what about scrollintoview command? Not sure if thats IE specific.

document.getElementById("SomeName").scrollIntoView(true);




回答2:


You could set the Window Location to include the # anchor, and the browser will scroll to it.

Window.Location = "http://yourSite.com/YourPage.html#SomeName";


来源:https://stackoverflow.com/questions/1804474/div-scroll-to-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!