homepage Welcome to WebmasterWorld Guest from 54.226.0.225
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Find Current Browser Window Position
The y value for the top of current user position in browser window
rover




msg:3415079
 6:39 pm on Aug 6, 2007 (gmt 0)

I have a div that is hidden until the user clicks on one of the links to display it through a javascript function to toggle the css display value.

Right now it will display at the top left corner which is fine on shorter pages where the user doesn't scroll down.

But if the user has scrolled down the page several times, and then clicks on the link, it will display the div way at the top of the page where it can't be seen (because the user has scrolled down so far).

Is there any javascript that allows you to extract the current y value for the content that is currently being displayed at the top of the browser window?

So, if the user had scrolled down 1500px from the top of the page, then I could get this y value of 1500 so I could then set things up to place the div right at the top based on where the user is currently viewing the page?

Or is there a way to get a div to always display at the top of the browser window currently being viewed regardless of how far down the user has scrolled?

 

WesleyC




msg:3415123
 7:18 pm on Aug 6, 2007 (gmt 0)

Try:

.pageTop
{
position: fixed;
top: 0px;
left: 0px;
}

<div class="pageTop">
I'm stuck to the top of the page!
</div>

rover




msg:3416168
 8:48 pm on Aug 7, 2007 (gmt 0)

Sorry, I didn't explain it well enough. I want the div to show up at the location where the user has scrolled down to. I found the following to get the value for how far down the user has scrolled:

Microsoft Internet Explorer:
document.body.scrollTop

Other Browsers:
window.pageYOffset

Gibble




msg:3416172
 8:53 pm on Aug 7, 2007 (gmt 0)

That's what position:fixed does.

rover




msg:3418112
 5:38 pm on Aug 9, 2007 (gmt 0)

Thanks. I see now that it does work for most browsers but IE6. So I have to put together something using document.body.scrollTop with javascript specifically for IE6 to get around this. Thanks very much for your help.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved