1

I am using jquery uimodaldialog and this is setting

$("#dialog").dialog({
    autoOpen : false,
    minWidth : 700,
    show : {
        effect : "fade",
        duration : 1000
           },
    hide : {
        effect : "fade",
        duration : 1000
           },
    close : function(event, ui) {
    },
});

I am calling with this

 $('.mylink').on('click', function() {
 $( "#dialog" ).dialog( "open");

Now on first click it shows at center of page .

if I click again then it goes about 200px upwards.

On further clicking it says there

1
  • 1
    Does the content of $( "#dialog" ) element changes in between? Commented Jan 7, 2015 at 7:17

3 Answers 3

1

HTML

<input type="button" class="mylink" />
<div id="dialog">Hello</div>

jQuery

$(document).ready(function () {
    $("#dialog").dialog({
        autoOpen: false,
        minWidth: 700,
        show: {
            effect: "fade",
            duration: 1000
        },
        hide: {
            effect: "fade",
            duration: 1000
        },
        position: {
            my: "center",
            at: "center",
            of: window
        },
        close: function (event, ui) {},
    });
    $('.mylink').on('click', function () {
        $("#dialog").dialog("open");
    });
});

Working Demo http://jsfiddle.net/cse_tushar/k4LLM/1/

Reference http://api.jqueryui.com/dialog/#option-position

Sign up to request clarification or add additional context in comments.

3 Comments

i don't know but i tried same coding puting in my files. First time it displays at correct position but next time display about 200px upwards. any idea which thing have been iterfering
can i add position with .dialog('open') so that i gets value from there not from default
click here this might help you
0

You can fix the position of dialog by following code

$("#dialog").dialog({
autoOpen : false,
minWidth : 700,
position: { 
    my: 'top',
    at: 'top',
    of: $('#some_div')
  }
show : {
    effect : "fade",
    duration : 1000
},
hide : {
    effect : "fade",
    duration : 1000
},
close : function(event, ui) {
},
});

You can find help about jquery position at http://api.jqueryui.com/position/

3 Comments

i try that but first time postion is right like defined , then next time is upwards than previous position
what value you have set for my , at and of ?
same as yours , is there any way to add postion with dailog.open
0

If you have dynamic height of contents in it. I think dialog can be changed second click. for solving it, use height option of dialog.

$("#dialog").dialog({
    autoOpen : false,
    minWidth : 700,
    height : 500, //it should be size of your contents
    show : {
        effect : "fade",
        duration : 1000
           },
    hide : {
        effect : "fade",
        duration : 1000
           },
    close : function(event, ui) {
    },
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.