如何将元素位置传递给jquery UI对话框 [英] How do I pass a an element position to jquery UI dialog

查看:79
本文介绍了如何将元素位置传递给jquery UI对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元素列表,当点击每个元素时,我希望我的jQueryUI对话框弹出 旁边 点击的列表元素。

I have a list of elements and when clicking on each one I would like my jQueryUI dialog box to pop up next to the list element that was clicked on.

$( "#selector" ).dialog({ draggable: false,
              width: 250,
              autoOpen: false,
              position: [e.pageX,e.pageY] });

$(".openDialog").click(function(e){
        console.log('I need the cooridnates x:'+e.pageX+' and y:'+e.pageY+'to be passed to the dialog box');
        $( "#selector" ).dialog("open");
});

我可以获得我需要的坐标,但是我无法将它们传递给对话框init。

I can get the coordinates I need, but I'm having trouble passing them to the dialog init.

想深入了解这一点。

提前致谢!

推荐答案

由于您想要显示单击元素旁边的对话框,您应该推迟设置对话框的位置,直到该信息可用,即在您的事件处理程序中:

Since you want to show the dialog next to the clicked element, you should defer setting the dialog's position until that information becomes available, i.e. in your event handler:

$("#selector").dialog({
    draggable: false,
    width: 250,
    autoOpen: false
});

$(".openDialog").click(function(e) {
    $("#selector").dialog("option", "position", [e.pageX, e.pageY])
                  .dialog("open");
});

这篇关于如何将元素位置传递给jquery UI对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆