Is it possible to show a qtip with a function call?

早过忘川 提交于 2019-12-10 18:42:21

问题


I am currently trying to create a text selection script so that people can mark a text and then let it being inserted into a form.

Thus I want to show a popup with a link "send to form", but I am having problems creating a tooltip with qtip (which I am using everywhere on my site) from my script which finds out if a text has been marked or not (there shall not be a link if my script cannot copy anything).

I am using this script for the selection detection: http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html

And where there currently is a an alert, there shall be a call to a qtip later:

Kolich.Selector.mouseup = function(){
    var st = Kolich.Selector.getSelected();
    if(st!=''){
        alert("You selected:\n"+st); // here will be showQTipAtMouseButtonFixed()
    }
}

Now the problem seems to be that whole qtip is focussed on hover. I can of course wrap a function around the .qtip() call, but this does not really solve the problem. Then the tooltip will be attached to my function and still showed only when I hover the element it is attached to.

This would be the qtip with wrapped function

function showQTipAtMouseButtonFixed() {
    $('#content').qtip({
        content: 'Hello!',
        position: {
            target: 'mouse',
            adjust: { mouse: false }
        },
        hide: {
            fixed: true
        },
        style: {
            tip: true,
            classes: 'ui-tooltip-red'
        }
    });
}

Using this instead of "#content" (which I saw in related posts) does not work either.

But I want it to be active in background all the time and display when the Kolich.Selector says "And now you are displayed!".

I also found a hint on show: 'click' via Google, but that’s not the solution either. It only works when you really assume a click, but in my case it’s rather double-click or mouse moving or keyboard.

Is this possible with qtip or do I have to use CSS display from scratch?


回答1:


Have you tried qtip's "show" function?

function showQTipAtMouseButtonFixed()
{
   $('#target').qtip({
       // your options

       show: '',
       hide: '',

       content: {
            prerender: true, // important
            text: 'Whatever you want to display'
       }
   }).qtip('show');
}


来源:https://stackoverflow.com/questions/9535028/is-it-possible-to-show-a-qtip-with-a-function-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!