How to keep jquery tools overlay centered on resizing page?


I am currently trying to learn how to use overlays and have been using this tutorial to help me.

The issue is that, while this tutorial keeps the overlay at a fixed position vertically while scrolling the page, it does not keep it centered horizontally while resizing the width of the page.

Is anyone familiar with this tool? Can it be tweaked to make it remain centered horizontally when a page is resized?

Thanks alot!
Who is Participating?
GaryConnect With a Mentor Commented:
There are a number of dialog plugins for jquery.
I have an article on EE about lightboxing images, that can be extended to any element (I do have an extended version but haven't got round to adding the new version)
Have a look here - this is for images, but is just an example.
According to their docs use this in the init config.

left : "center"
CFbubuAuthor Commented:
Thanks. I did try that before,  left : "center" , using the tutorial example, and it did not work when the page was resized. The issue is, the overlay popup IS centered when it is first opened, but will not remain centered when page is resized.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Having a look through the code it only centres based on the width of the browser at that moment.
Rather than messing with the core code I would just override the css after the dialog has been initiated and set the left property to 50% and give it a margin-left equal to half the width of the dialog.  You do need to know the width of the dialog - there is no other way to do it if it is a dynamic width.
Of course you could go further and get the width of the element and use that for the margin-left.
Either that or use one of the other jquery dialog plugins that do center.
CFbubuAuthor Commented:
I did try to override the css after the dialog has been initiated, but it refuses to respond to the set left property to 50% no matter what I do. :( The dialog box just refuses to budge from it's initial centered position when the window is resized.

I am at a lost and would truly be very grateful if you could show me how you got it to work.
I didn't that was just theory, will have a look now
Can you post a link to your page or post what you are using to call the dialog.
The jquery would be this.

Open in new window

CFbubuAuthor Commented:
Thanks.  But how do I integrate your solution into my page? I have printed out the code of my page below. Thank you so very very much.

<script src=""></script>

This is the current script code on my test tutorial page:

$(document).ready(function() {
    var triggers = $(".modalInput").overlay({

      // some mask tweaks suitable for modal dialogs
      mask: {
        color: '#ebecff',
        loadSpeed: 200,
        opacity: 0.9
left: "center",

        fixed: true,

      closeOnClick: true
    var buttons = $("#yesno button").click(function(e) {

      // get user input
      var yes = buttons.index(this) === 0;

      // do something with the answer
      triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
    $("#prompt form").submit(function(e) {

      // close the overlay

      // get user input
      var input = $("input", this).val();

      // do something with the answer

      // do not submit the form
      return e.preventDefault();

This is the current css:

  .modal {
    border:2px solid #333;

    -moz-box-shadow: 0 0 50px #ccc;
    -webkit-box-shadow: 0 0 50px #ccc;

 .modal h2 {
    background:url(/media/img/global/info.png) 0 50% no-repeat;
    padding:10px 0 10px 45px;
    border-bottom:1px solid #333;

This is the current body html:


      <a href="#" class="modalInput" rel="#yesno">Yes or no?</a>
  <button class="modalInput" rel="#yesno">Yes or no?</button>
  <button class="modalInput" rel="#prompt">User input</button>

<!-- yes/no dialog -->
<div class="modal" id="yesno">
  <h2>This is a modal dialogdddd</h2>

    You can only interact with elements that are inside this dialog.
    To close it click a button or use the ESC key.

  <!-- yes/no buttons -->
    <button class="close"> Yes </button>
    <button class="close"> No </button>

<!-- user input dialog -->
<div class="modal" id="prompt" >
  <h2>This is a modal dialog</h2>

    You can only interact with elements that are inside this dialog.
    To close it click a button or use the ESC key.

  <!-- input form. you can press enter too -->
    <input />
    <button type="submit"> OK </button>
    <button type="button" class="close"> Cancel </button>
  <br />

After examining his code all I can say is blah
His code is closed to any user extending of the code. i.e. he his adding triggers to the elements that are not exposed because everything is handled in his code
Counter intuitive to the way jquery plugins work.
I did try passing a margin-left but it wasn't accepted.

Is there a specific reason to using this plugin.
I suppose I could add an handler to the dialog to watch for when it is shown, but I feel like I'm chasing my tail.
CFbubuAuthor Commented:
Very sorry for your trouble.

I wanted to find a plugin that will allow me to popup and overlay that holds content that is centered on the page and that stays vertically in one spot. It would be gone if the user clicks anywhere outside the overlay content box but will remain if the user clicks anywhere inside the content box unless the user clicks on a close button....

If seems like it is impossible to find such a solution. I have spent countless hours finding for such an overlay.

The closest I could find was this overlay.

It works perfect for what I am looking for. The only BIG issue is that on chrome and safari browsers, when the overlay opens, it produces a colored border around the content box and when the overlay contant closes, it leaves a colored border over the text that was clicked on to trigger the overlay. This colored border will only disappear after a second click..... This does not happen on explorer or firefox.
CFbubuAuthor Commented:
you are right. By searching 'dialog plugins', I see a whole lot of other options out there!..Let me do a little more research from the other sites. Thanks for pointing me in the right direction. Let me get back to you with what I find and what was successful for me. :)
CFbubuAuthor Commented:
Thanks for passing me information that proved helpful to me.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.