[英]Positioning jquery ui dialog box
如何相对于body内的div元素定位jquery ui对话框?
Perhaps this might get you the idea how to do it: 也许这可能会让你知道如何做到这一点:
HTML: HTML:
<div id="one" class="divs"></div>
<div id="two" class="divs"></div>
CSS: CSS:
.divs {
float: left;
height: 48px;
width: 80px;
border: 1px solid #55f;
}
JS: 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. jQuery offset ()返回相对于document的元素postion,而position ()返回相对于offset的父元素。
$('#dialog').position({of: $('#your_div')});
http://api.jquery.com/offset/ shows how to get coordinates of a div element. http://api.jquery.com/offset/显示了如何获取div元素的坐标。 but direct usage might not be enough as this depends on layout structure (floats, margins, etc). 但直接使用可能还不够,因为这取决于布局结构(浮点数,边距等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.