Move div to top of viewport

hi, all.

I got a div, I’d like some code to be executed onClick, that’d move the div to the top of the viewport (not to the top of the page), kinda like a “vertical float”.

Is there a way to do this? I’ve seen annoying menus/ advertisements that stick to the top of the window even if you scroll down.

any help appreciated, thanks!!!

:slight_smile:

If you apply a css style of ‘position:fixed;top:0’ you will only annoy visitors who have firefox, opera, safari and IE7.

If you want to annoy everyone, get the document.body.scrollTop or document.documentElement.scrollTop or the window.pageYoffset to calculate the amount the page has scrolled and position your element top to that amount of pixels.

Speak for yourself.

What do find annoying about a menu with fixed position?

What do find annoying about a menu with fixed position?

Not a thing- it is the part about moving a div to the top of the viewport I find problematic.
I prefer position:fixed to be, well, fixed.

Ah - yes I admit that many people did not like the “floater” style menus - even tho they are fun to create :wink:

nicc9, for examples of “floater” menus (and how to position an element relative to the ‘viewport’) go to my Toys page and search for “floater”. For examples of “fixed” elements go to my Toys page and search for “fixed”.

yeah, I don’t reallly wanna do that.

i’m moving the div while it’s hidden, then make it appear when it’s already in place.

I just want it to appear in the right position, then if the user scrolls down i don’t care if you can’t see it any more.

thanks, Mike, I’ll check it out! :slight_smile: