Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui dialog fixed positioning

I needed the dialog to maintain its position fixed even if the page scrolled, so i used the extension at http://forum.jquery.com/topic/dialog-position-fixed-12-1-2010 but there's 2 problems with it:

  • it flickers in IE and Firefox on page scroll (in Safari/Chrome it's fine)

  • on closing and then reopening, it looses its stickyness and scrolls along with the page.

Here's the code i'm using for creating the dialog:

$('<div id="'+divpm_id+'"><div id="inner_'+divpm_id+'"></div><textarea class="msgTxt" id="txt'+divpm_id+'" rows="2"></textarea></div>')                 .dialog({                 autoOpen: true,                 title: user_str,                 height: 200,                 stack: true,                 sticky: true //uses ui dialog extension to keep it fixed      }); 

And here's the code i'm using for reopening it:

jQuery('#'+divpm_id).parent().css('display','block'); 

Suggestions/solutions?

Thanks

like image 514
scc Avatar asked Apr 17 '10 03:04

scc


People also ask

What is UI positioning?

The jQuery UI . position() method allows you to position an element relative to the window, document, another element, or the cursor/mouse, without worrying about offset parents.

How do you check if jQuery dialog is initialized?

dialog( { ... } ); Then check for the class when needed: if ($("selector"). hasClass("initialized")) { ... }

What is dialog close?

Dialog close() Method The close() method closes the dialog. Tip: This method is often used together with the show() method.


1 Answers

I tried some of the solutions posted here, but they don't work if the page has been scrolled prior to the dialog being opened. The problem is that it calculates the position without taking into account the scroll position, because the position is absolute during this calculation.

The solution I found was to set the dialog's parent's CSS to fixed PRIOR to opening the dialog.

$('#my-dialog').parent().css({position:"fixed"}).end().dialog('open'); 

This assumes that you have already initialized the dialog with autoOpen set to false.

Note, this does not work if the dialog is resizable. It must be initialized with resizing disabled in order for the position to remain fixed.

$('#my-dialog').dialog({ autoOpen: false, resizable: false }); 

Tested this thoroughly and have found no bugs so far.

like image 133
Scott Greenfield Avatar answered Oct 01 '22 10:10

Scott Greenfield