2012-03-02 56 views
3

我目前正在尝试创建文本选择脚本,以便人们可以标记文本,然后让它插入到表单中。是否可以通过函数调用显示qtip?

因此,我想显示一个链接“发送到表单”的弹出式菜单,但我在创建工具提示时出现了问题(从我的网站到处使用qtip),它发现文本是否有被标记与否(如果我的脚本不能复制任何内容,则不应该有链接)。

我使用这个脚本的选择检测:http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html

哪里目前存在的alert,应当有一个qtip后来打电话:

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

现在的问题似乎是整个qtip专注于悬停。我当然可以围绕.qtip()调用打包函数,但这并不能真正解决问题。然后,工具提示将附加到我的功能,但只有当我悬停它所连接的元素仍然显示

这将与包装的函数

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

使用的this代替"#content"(这是我在相关的帖子看到的)也不行的qtip。

但我希望它始终处于活动状态,并在Kolich.Selector显示“现在显示!”时显示。

我还发现show: 'click'via Google暗示,但这也不是解决方案。它只适用于你真的假设点击,但在我的情况下,它只是双击或鼠标移动或键盘。

这是可能与qtip或我必须从头使用CSS display

回答

5

您是否尝试过qtip的“show”功能?

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

     show: '', 
     hide: '', 

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

谢谢@patrick ....添加prerender后:true,qtip工作! 它究竟做了什么? – ram 2014-01-16 10:28:40

相关问题