jquery - 使用 qtip jquery 工具提示插件时,屏幕上只有一个工具提示处于事件状态

标签 jquery qtip

我在页面上的多个元素(图像)上使用 jquery qtip 工具提示。我试图在特定时间仅在页面上显示一个工具提示。如果显示一个工具提示并且已触发另一个工具提示打开,则当前打开的实例应关闭。 I have found this in the documentation and have set solo: true但是,页面上仍然出现工具提示的多个实例。这是我的 jquery:

<script type="text/javascript">
        $(document).ready(function () {

            //****** tooltips **********
            $('img.help').hover(function () {

          // Destroy currrent tooltip if present
          //if ($(this).data("qtip")) $(this).qtip("destroy");

          $(this) // Set the links HTML to the current opposite corner
            .qtip({
                content: 
                {
                    text: 'this is the tooltip, better to use the alt attribute of the image or use html div content somewhere on the page', 
                        title: {
                        text: 'This toolip title',
                        button: 'Close'
                        }
                },
                position: {
                    corner: {
                        tooltip: 'bottomLeft', // Use the corner...
                        target: 'topRight' // ...and opposite corner
                    }
                },
                show: {
                    solo: true,
                    when: false, // Don't specify a show event
                    ready: true // Show the tooltip when ready
                },
                hide: false, // Don't specify a hide event
                style: {
                    border: {
                        width: 5,
                        radius: 10
                    },
                    padding: 10,
                    textAlign: 'left',
                    tip: true, // Give it a speech bubble tip with automatic corner detection
                    name: 'blue' // Style it according to the preset 'cream' style
                    // name: 'light' // Style it according to the preset 'cream' style
                }
            });


      });

});

html:

<div>
                    <div class="left sublabel">
                        Parameds</div>
                    <div class="left help">
                        <img src="images/help.png" class="help" /></div>
                    <div class="clear">
                    </div>
                </div>
                <div>
                    <div class="left sublabel">
                        Vision</div>
                    <div class="left help">
                        <img src="images/help.png" class="help" /></div>
                    <div class="clear">
                    </div>
                </div>

最佳答案

我的猜测是,即使您将solo设置为true,它们仍然显示的原因是因为qtip的所有实例都具有相同的类。在处理同一页面上的多个工具提示时,我的 qtips 实例上总是有不同的类名,这种方式对我很有效。

如果由于某种原因这不起作用,您可以尝试隐藏 beforeShow api 方法中的所有工具提示。

$('#tooltip').qtip({
   ...
   api: {
      beforeShow: function() {
         $('img.help').qtip("hide");
      }
   }
});

关于jquery - 使用 qtip jquery 工具提示插件时,屏幕上只有一个工具提示处于事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7585386/

相关文章:

jquery - 验证 jQuery 插件,字段不是必需的

javascript - 从 javascript 对象获取列表

jquery - Qtip基础问题

javascript - 工具提示(qTip)未关闭,jQuery

validation - jQuery验证UI插件不包括qTip资源

javascript - 如何检查选择器是否有qtip?

jquery - HTML5 Canvas 100% 视口(viewport)宽度高度?

javascript - 无需修改核心文件的 WordPress 管理员自定义

javascript - 将多个点击处理程序合并为一个

jquery - 如何关注qtip(jquery插件)中的元素