如何相对于body内的div元素定位jquery ui对话框?
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.
$('#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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.