I am trying to use the jQuery dialog UI library in order to position a dialog next to some text when it is hovered over. The jQuery dialog takes a position parameter which is measured from the top left corner of the current viewport (in other words, [0, 0] will always put it in the upper left hand corner of your browser window, regardless of where you are currently scrolled to). However, the only way I know to retrieve the location is of the element relative to the ENTIRE page.

以下是我目前掌握的情况.position.top被计算为1200左右,这使得对话框远远低于页面上的其他内容.

$(".mytext").mouseover(function() {
    position = $(this).position();
    $("#dialog").dialog('option', 'position', [position.top, position.left]);
}

How can I find the correct position?

谢谢

推荐答案

查看一些jQuery插件,了解对话框的其他实现.Cluetip似乎是一个功能丰富的工具提示/对话框样式插件.第四个演示听起来与您正在try 的类似(尽管我看到它没有您想要的精确定位选项)

Jquery相关问答推荐

在shiny 的datatable列中启用智能搜索

逐个交换图像

多个 AJAX 调用;获取所有失败的呼叫

第一次单击后,Ajax addEventListener 停止工作

在 for 循环中分配点击处理程序

提交前添加 POST 参数

jQuery从字符串中删除字符串

jQuery:获取所选单选按钮的父 tr

jQuery绑定到粘贴事件,如何获取粘贴的内容

JavaScript / jQuery:测试窗口是否有焦点

字符串化(转换为 JSON)具有循环引用的 JavaScript 对象

使用jquery设置di​​v标签的值

jquery变量语法

jQuery:获取父母,父母ID?

页面重新加载后,如何使用 twitter bootstrap 保持当前选项卡处于活动状态?

为什么使用 jQuery on() 而不是 click()

JQuery:如果 div 可见

jQuery slideUp().remove() 在删除发生之前似乎没有显示 slideUp 动画

javascript,是否有像 isArray 这样的 isObject 函数?

Jquery 日期 Select 器 z-index 问题