获取名为qTip的元素?

时间:2012-05-19 22:01:34

标签: javascript jquery html object qtip

我想获得调用qtip弹出窗口的元素。在文档here中,它可以让您设置位置。我想使用像$(this).find('.icon')这样的jquery选择器来设置位置。问题是this不是调用qtip的元素(我认为它是window)。

有谁知道如何获得调用它的句柄(就像我将目标设置为false一样)?

感谢。

在qtip源代码中我发现了这个: if(config.position.target === false) config.position.target = $(this);

1 个答案:

答案 0 :(得分:0)

这是我提出的解决方案,似乎有效。如果我修改了qtip脚本,可能有更好的方法可以做到这一点,但我想单独留下它。

$(".report-error").qtip(
{
    content: 'test content',
    position:
    {
        adjust:
        {
            screen: true
        },
        target: false, //it is changed in the 'beforeRender' part in api section. by leaving it as false here in the qtip it will set it as the position I need using $(this)
        corner:
        {
            target: 'bottomMiddle',
            tooltip: 'topRight'
        }
    },
    show:
    {
        when:
        {
            event: 'click'    
        }
    },
    style:
    { 
        name: 'cream',
        tip:
        {
            corner: 'topRight'
        },
        padding: 0,
        width: 400,
        border:
        {
            radius: 5,
            width: 0
        }
    },
    hide:
    {
        when:
        {
            event: 'unfocus'
        }
    },
    api:
    {
        beforeRender: function() { //get the position that qtip found with $(this) in it's script and change it using that as the start position

            this.options.position.target = $(this.elements.target).find('.icon');
            this.elements.target = this.options.position.target; //update this as well. I don't actually know what it's use is
        }
    }
});

它现在正在http://wncba.co.uk/results/

的网站上工作