更改提示工具提示的重力/位置

Change the gravity/position of tipsy tooltip?

本文关键字:位置 提示 工具提示      更新时间:2023-09-26

有没有办法编辑醉酒的位置或重力(我不知道什么是正确的)?该插件本身有几个重力选项,您可以通过脚本分配这些选项:

nw | n | ne | w | e | sw | s | se

我目前正在使用s位置,正如您在小提琴中看到的那样:http://jsfiddle.net/cnLW8/

但我想知道 Tipsy 的位置是否可以以它在元素中心显示的方式进行编辑。不是在旁边,在上面或之外,而是相对靠近中心?

目前,我通过将类的 css 属性设置为.tipsy来执行此操作:

.tipsy{
    margin-top: 30px;
}

但我认为有一些更聪明的解决方案,通过脚本或其他东西对其进行编辑......

欢迎任何帮助或建议。

我无法对此进行测试,但我认为在 tipsy.js 中向开关块添加一个新案例就可以了。

我添加了案例 z,使用 s 中的数学来获取左值,从 w 中添加数学来获得最大值,结果应该是死点。只需将案例添加到您的 js 文件中,然后使用案例 z 重新加载它。

switch (gravity.charAt(0)) {
                case 'n':
                    tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
                    break;
                case 's':
                    tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
                    break;
                case 'e':
                    tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
                    break;
                case 'w':
                    tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
                    break;
                case 'z':
                    tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width / 2 - actualWidth / 2};
                    break;
            }