Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: open

Message Too Old, No Replies

Find Current Browser Window Position

The y value for the top of current user position in browser window

     

rover

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

10+ Year Member



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

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

5+ Year Member



Try:

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

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

rover

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



That's what position:fixed does.

rover

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

10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month