Place element at top of viewport

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Place element at top of viewport

Post by pickle »

Hi all,

I've got a password change form inside an element that will appear when an icon is clicked. This form will be used on a page with a potentially long list, so the user might scroll down a bit first.

I've currently managed to get this form to appear at the top of the page - even if the top of the page is outside the current user's viewport. Is there a way - either with CSS or Javascript - to ensure the form will always appear inside what the user is currently looking at? I'm sure there's a window variable available to Javascript, but I can't find it anywhere.

Thanks for any & all help.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you referring to something like the floating pane we have from the "RTM-ize" button?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Yep, exactly. I hadn't noticed it always shows up in the viewport.

For posterity's sake, the solution was:

Code: Select all

window.pageYOffset
Thanks.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply