在包含目标的区域之外隐藏qTip

dmr*_*dmr 5 jquery hide mouseleave qtip qtip2

我想仅在鼠标悬停目标(<span class="percent100">)上显示qtip ,但我想保持可见,直到我将鼠标移动到一般包含元素(<div class="profileArea")之外.这是我尝试过的,但它不起作用.

HTML:

//other HTML

//don't hide tooltip if anywhere in this div
<div class="profileArea">
    <span class="profileInner">Your Profile: 0 
         <span class="fullProfileBar">
            <span class="completedProfileBar"></span>
         </span>
         //start showing when hover over this span
         <span class="percent100"> 100%</span>
     </span>
</div>

//other HTML
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$('.percent100').qtip({
    id: 'progressBarTooltip',
     content: {
         text: 'Text Here'
     },
     position: {
          my: 'top right',
          at: 'bottom right',
          target: $('.percent100')
     },
     show: {
        event: 'mouseover' //shows when hover .percent100
     },
     hide: {
        fixed: true,
        //trying to hide when leave 
        target: $("div[class!='profileArea']")
     },
});
Run Code Online (Sandbox Code Playgroud)

Car*_*ira 3

您需要执行类似以下内容: http ://jsfiddle.net/78zmG/2/

// Create the tooltips only when document ready
$(document).ready(function() {
    // MAKE SURE YOUR SELECTOR MATCHES SOMETHING IN YOUR HTML!!!
    $('a').qtip({
        hide: {
            delay: 400
        },
        events: {
            render: function(event, api) {
                // All elements with class 'safe' will set the 'safe' flag in the API cache
                $(document.body).delegate('.safe', 'mouseenter mouseleave', function(event) {
                    api.cache.safe = event.type === 'mouseenter';

                    // This will hide the tooltip if we mouse out of the "safe" elements
                    if(!api.cache.safe) { api.hide(event); }
                });
            },
            hide: function(event, api) {
                 // Check we're currently on a "safe" element, and stop the hide if so
                if(api.cache.safe) {
                    try { event.preventDefault(); }
                    catch (e) {} // Needed for old IE and jQuery versions
                }
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

当您越过红色方块时,检查 qtip 是否保持打开状态。

  • 将 jquery delegate 更改为 on 方法。“从 jQuery 1.7 开始,.delegate() 已被 .on() 方法取代。” (2认同)