如何将页面加载到页面的中间(而不是顶部)? [英] How to have a page load to the middle of the page (instead of top)?
本文介绍了如何将页面加载到页面的中间(而不是顶部)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让页面在页面中间的某个div处打开,而不是在顶部...
I'd like for the page to open at a certain div halfway down the page, not at the top...
我有类似的东西:
<div id="d1">
<div id="d2">
<div id="d3">
<div id="d4">
<div id="d5">
<div id="d6">
如何在#d4页面打开页面,而不是顶部? (除了在网址末尾添加#d4)
How can I get the page to open at #d4, instead of the top? (Besides adding #d4 to the end to the URL...)
我想象一定有一些简单的方法来做到这一点,但我不知道如何去寻找一个解决方案! HTML,javascript?非常感谢任何帮助。
I imagine there must be some easy way to do this, but I can't figure out how to go at searching for a solution! HTML, javascript? Any help is greatly appreciated.
推荐答案
<script>
function ScrollToElement(theElement){
var selectedPosX = 0;
var selectedPosY = 0;
while(theElement != null){
selectedPosX += theElement.offsetLeft;
selectedPosY += theElement.offsetTop;
theElement = theElement.offsetParent;
}
window.scrollTo(selectedPosX,selectedPosY);
}
</script>
http://radio.javaranch.com/pascarello/2005/01/09/1105293729000.html
这篇关于如何将页面加载到页面的中间(而不是顶部)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文