SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot nicc9's Avatar
    Join Date
    Jan 2005
    Location
    New Orleans, LA
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!!!!


  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo
    If you apply a css style of 'position:fixed;top:0' you will only annoy visitors...
    Speak for yourself.

    What do find annoying about a menu with fixed position?

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Zealot nicc9's Avatar
    Join Date
    Jan 2005
    Location
    New Orleans, LA
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo View Post
    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.
    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.

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah - yes I admit that many people did not like the "floater" style menus - even tho they are fun to create

    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".

  7. #7
    SitePoint Zealot nicc9's Avatar
    Join Date
    Jan 2005
    Location
    New Orleans, LA
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster View Post
    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".
    thanks, Mike, I'll check it out! :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •