开发者

Javascript ScrollTop Function help

i got the function below which popups up a window开发者_如何转开发 but fails to scroll the main page to the appropiate div height.

function open_window(getDiv) 
{
var objDiv = document.getElementById(getDiv);
document.scrollTop = objDiv.scrollHeight;
new_window = open("http://www.mysite.com/","MySite","width=610,height=510,left=600,top=400");
new_window.focus();
}


If I'm understanding this right (You want to scroll the page to wherever the div is on the page), then you are using the wrong property from objDiv.

scrollHeight is used to figure out what the height of the contents inside of the container is. The property you are looking for is offsetTop. Here is an updated version of your code:

function open_window(getDiv) 
{
var objDiv = document.getElementById(getDiv);
document.scrollTop = objDiv.offsetTop;
new_window = open("http://www.mysite.com/","MySite","width=610,height=510,left=600,top=400");
new_window.focus();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜