对话框的Jquery位置在<li> </li>之上

时间:2012-12-13 01:27:41

标签: modal-dialog

我创建了代码,用于在点击div时显示jquery对话框。此时对话框在点击位置后的5个点处弹出。

我试图从li的顶行显示对话框,这意味着li的顶部边框应与对话框的顶部边框对齐。有人可以指出我正确的逻辑来找出如何通过获得li顶部边界位置来打开对话。

  <div class="editionDetailAction">Action for Item 1</div>
<div class="editionDetailAction">Action for Item 2</div>
<div class="editionDetailAction">Action for Item 3</div>
<div class="editionDetailAction">Action for Item 4</div>



<div id="actionsPopup">
    <ul><li><a href="http://www.google.com">Add xyz</a></li></ul>
    <ul><li>Manage xyz</li></ul>
    <ul><li>Show xyz</li></ul>
</div>


.editionDetailAction { width: 130px; height: 30px; border: solid 1px #ddd; }
.actionsPopup .ui-dialog-titlebar { display:none; }



$(document).ready(function () {
    $('.editionDetailAction').click(function (e) {
        $("#actionsPopup").dialog("option", { position: [e.pageX+5, e.pageY+5] });
    });

    $("#actionsPopup").dialog({
            autoOpen: false,  
dialogClass: 'actionsPopup',
        maxWidth:100,
                    maxHeight: 100,
                    width: 100,
        height: 80,
resizable: false,


    });
    $(".editionDetailAction").bind("click", function () {
        $("#actionsPopup").dialog('open'); 
    });
    $(".actionsPopup").bind("mouseover", function () {
        $("#actionsPopup").dialog('open');
    }); $(".actionsPopup").bind("mouseleave", function () {
        $("#actionsPopup").dialog('close');
    });

    $(".editionDetailAction").bind("mouseleave", function () {
        $("#actionsPopup").dialog('close'); 
    });


   });

1 个答案:

答案 0 :(得分:1)

试试这个:

$('.editionDetailAction').click(function() {
    var pos = $(this).position();
    $("#actionsPopup").dialog("option", {
        position: [pos.left+5, pos.top+5]
    });
});

参见示例:http://jsfiddle.net/Twisty/DZm9d/1/