Positioning jquery ui dialog box
How to position jquery ui dialog box with respect to a div element inside开发者_运维问答 the body?
Perhaps this might get you the idea how to do it:
HTML:
<div id="one" class="divs"></div>
<div id="two" class="divs"></div>
CSS:
.divs {
float: left;
height: 48px;
width: 80px;
border: 1px solid #55f;
}
JS:
$(document).ready(function(){
var $div = $('#two');
var left = $div.offset().left;
var top= $div.offset().top;
$('<p>Some dialog</p>').dialog({position: [left + 20, top + 20]});
});
Here is the link to demo.
jQuery offset() returns element postion relative to document, while position() returns relative to offset parent.
Use jQuery position function or jQuery UI one
$('#dialog').position({of: $('#your_div')});
http://api.jquery.com/offset/ shows how to get coordinates of a div element. but direct usage might not be enough as this depends on layout structure (floats, margins, etc).
精彩评论