Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Keep a div in middle of page

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29755
    noahgelman
    Participant

    I have a div that’s positioned absolutely relative to the body. I want it to stay a certain distance from the top. How would I accomplish that?

    Here are two variables I have now to keep it in the center on page load. First I grab the window height, and then I divide it by 2 and subtract half the div height. That centers it.

    Code:
    var = $windowHeight = $(window).height();
    $navHeight = $windowHeight/2-122;

    That’s all fine and dandy and I can live with that, its fixed so its still in place even while scrolling. The problem is that this is static. Meaning if they re-size the window to any dimension that’s different then it was when the page loads, it now isn’t in the middle anymore. Any ideas?

    #81174
    noahgelman
    Participant

    Thanks for the help. What i need doesnt have to be absolutely in the center so the left isn’t needed but the top parts did. I haven’t tried this out, but I’m going to mark this as solved.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.