views:

728

answers:

4

I am trying to open a modal jquery dialog using jquery 1.4 and jquery-ui-1.8rc3.custom.js

The dialog opens up with no issues, in all browsers, but in IE 7 and 6, after the dialog opens up, the window scrolls itself to the buttom... I tried scrolling the window up back to the modal position but is very inconsistent. was using the following line of code after opening up the modal

window.scrollTo($('#selector').dialog('option', 'position')[0],$('#selector').dialog('option', 'position')[1]);

One weird thing I am noticing is that after I open the modal, the page becomes huge... as if some extra things adds up on the bottom .... and it eventually scrolls to the bottom. Any idea why this could be hapenning

in html

 <div id="selector">

        </div>

in document.ready

  $('#selector').dialog({
                bgiframe: true,
                autoOpen: false,
                width: 100,
                height: 100,
                modal: true,
                position: 'top'
            });

in js

  $('#selector').dialog('open');
A: 

Looks like you are missing the # in your selector:

window.scrollTo($('#selector').dialog('option', 'position')[0], $('#selector').dialog('option', 'position')[1]);

that might be why the window is scrolling to the left top corner.


Edit: I was just looking at the documentation and .dialog('option','position') default value is center.

position Type: String, Array Default: 'center'

Specifies where the dialog should be displayed. Possible values: 1) a single string representing position within viewport: 'center', 'left', 'right', 'top', 'bottom'. 2) an array containing an x,y coordinate pair in pixel offset from left, top corner of viewport (e.g. [350,100]) 3) an array containing x,y position string values (e.g. ['right','top'] for top right corner).

So you could get text or numbers returned using the position option and window.scrollTo() requires numbers. So try this instead:

var d = $(".ui-dialog").position();
window.scrollTo( d.left , d.top);
fudgey
Oh... I think I missed it when I copied the code onto stackoflow.com and edited it, it does have the '#' sign... Thanks for pointing it out though!
zoom_pat277
I have updated my answer.
fudgey
I am sorry, I did not get a chance to implement your suggestion till now. Give me few hrs and I will get back to you.Thanks a lot for getting back!
zoom_pat277
@fudgey - tried this and worked... but with a little tweak... had to usewindow.scrollTo($('#selector').closest('.ui-dialog').offset().left ,$('#selector').closest('.ui-dialog').offset().top );Thanks again for your idea! :)
zoom_pat277
A: 

Hi all,

I have had a similar situation where the dialog was opening where it should on the page, but the user was redirected to the bottom of the page. Basically, I forgot to include the appropriate css to match the jQuery UI JavaScript library. By doing this everything was ok. I imagine it's something like that, where there are styles set on elements on the jQuery css that are not set in your own css.

To debug the problem so I didn't have to include the whole jQuery UI css, I made two identical pages, one using the jQuery UI css and one not and just checked what was different in the css via Firebug on Firefox and added these styles to my css.

Hope it helps. Mag

Mag
A: 

Hi there - I was struggling with this issue too. I didn't use any theming so I didn't have this important CSS property:

position:absolute;

I added this to my CSS file and all works fine now:

.ui-widget { position: absolute; }
telecasterrok
A: 

Hi! If you're using an anchor tag like below to trigger the dialog

<a href="#" onclick="$(#id).dialog('open');">open dialog</a>

you want to add a

return false;

to the onclick attribute:

<a href="#" onclick="$(#id).dialog('open'); return false;">open dialog</a>

This helped me preventing the page jump (or page reloading to anchor '#').

bassim