Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7958345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:24:28+00:00 2026-06-04T04:24:28+00:00

Update I’ve just updated the jsFiddle so that you can see the pop up

  • 0

Update

I’ve just updated the jsFiddle so that you can see the “pop up” happening and how it’s never centered. It’s always 200px from top.

So if the user has scrolled down a long page and clicked to make the pop up happen, the pop up is back up at the top of the page – 200px instead of centered on the visible screen.

http://jsfiddle.net/JYgcj/40/

I’ll try out the answer below and update with results of that


I have a hidden div included in my layout as a partial

Here is the partial

A javascript function shows this div for showing the result of ajax requests

function showResultPopUpDiv(divId, title) {

    var popUpId = document.getElementById(divId);
    var popUpHeader = title;
    var originalDivHTML;
    var topPos = 200;
    var popUpWidth;
    var midPos;
    var leftPos;
    var spinnerOpts;

    //Insert header text & open pop up
    popUpId.style.display = "block";
    document.getElementById("ajaxResultPopUpHeaderText").innerHTML = popUpHeader;

    //Set position dimensions
    popUpWidth = popUpId.offsetWidth / 2;
    midPos = $(document).width() / 2;
    leftPos = midPos - popUpWidth;

    //Position pop up (center)
    popUpId.style.top = topPos + "px";
    popUpId.style.left = leftPos + "px";

    //Insert spinning loader code here
    ... //left out for brevity
}

If a view is longer than a single screen and the user has scrolled to the bottom and clicked the submit button, this div pops up but cannot be seen unless the user scrolls back to the top.

How do I get this to center on the window correctly wherever the page is currently scrolled to.

This question and others that I’ve investigated have not solved this for me. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:24:29+00:00Added an answer on June 4, 2026 at 4:24 am

    It sounds like what you want is a CSS position of “Fixed” (CSS Positioning 101). This will keep the object fixed relative to the viewport (the browser) rather than relative to the document. This will affect the way top and left behave.

    Make sure you have something like:

    #ajaxResultPopUpHeaderText {
        position: fixed; /* Make the position fixed to the viewport,
        so it stays in the same place no matter how much the user scrolls */
    }
    

    To centre on the viewport you need to calculate positions relative to the viewport. The full JSFiddle (forked from your original, with added content for scrolling and styling to keep the button with you as you scroll) has all of the JavaScript, but since you’re working with jQuery then you just need to use $(window) instead of $(document).

        //Set position dimensions
        var popUpHeight = popUpId.offsetHeight / 2;
        var centrePos = $(window).height() / 2;
        topPos = centrePos - popUpHeight;
        popUpWidth = popUpId.offsetWidth / 2;
        midPos = $(window).width() / 2;
        leftPos = midPos - popUpWidth;
    

    $(document) happens to work okay for width, because the document is generally 100% of the width, but you should use $(window) anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update I want to have an expression (XPath, or Regex Expression, similar) that can
[UPDATE] Was just an idiot mistake. See end for solution. I am trying to
UPDATE - I'm probably being daft, see my last update below. I just did
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
UPDATE : I updated the classes to look more like my actual model. When
UPDATE: Thanks for all your help guys! I just need to take a litte
UPDATE: Solution at bottom. I recently switched from using a set up such as
UPDATE: Thanks for the answers! I can't seem to figure it out, even with
Update Table1 set name = (select top 1 a.col from Table2 a where Table1.num

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.