简体   繁体   English

如何在内部 v-tooltip 悬停时关闭外部 v-tooltip

[英]How to close outer v-tooltip on inner v-tooltip hover

I have two tooltips, one is on an outer element, the other on the inner element like this:我有两个工具提示,一个在外部元素上,另一个在内部元素上,如下所示:

嵌套工具提示

How do I remove the outer tooltip when the inner tooltip is showing?显示内部工具提示时,如何删除外部工具提示?

Here's a Fiddle这是一个小提琴

The code is pretty standard, but keep in mind, sometimes v-tooltip places tooltips like a modal - on the body level, so the tooltips might not actually be nested.代码非常标准,但请记住,有时v-tooltip 会像模态一样放置工具提示 - 在正文级别,因此工具提示实际上可能不会嵌套。

<div id="app">
  <div v-tooltip="'Outer Tooltip'">
    Outer Area
    <div v-tooltip="'Inner Tooltip'">
      okokok
    </div>
  </div>
</div>

Here's what I've tried:这是我尝试过的:

On the Outer Tooltip I put a class like this:在外部工具提示上,我放了一个这样的类:

v=tooltip="{content:'Outer Tooltip', classes:['killOnOtherOpen']}"

And then on the inner tooltip:然后在内部工具提示上:

v=tooltip="getTextAndDoStuff()"
...
getTextAndDoStuff(){
    $('.killOnOtherOpen').close();
    return "Inner Tooltip";
}

But I get an Error:但我收到一个错误:

Error in render: "TypeError: $(...).close is not a function"渲染错误:“TypeError: $(...).close 不是函数”

I've tried it like so: .close;我试过这样: .close; - like close is not a function - but nothing happens, not even an error. - 就像 close 不是一个函数 - 但没有任何反应,甚至没有错误。

I'm looking for a more elegant or standard way to do this.我正在寻找一种更优雅或更标准的方式来做到这一点。 Adding a class and a method to each nested tooltip set will take a while.向每个嵌套的工具提示集添加一个类和一个方法需要一段时间。

You could fix this issue by using the stop modifier when handling the mouseover event, and add a boolean property called isOpen to show/hode the outer tooltip.您可以通过在处理mouseover事件时使用stop修饰符来解决此问题,并添加一个名为isOpen的布尔属性来显示/隐藏外部工具提示。

the stop modifier will prevent the event propagation stop修饰符将阻止事件传播

 console.clear() new Vue({ el: '#app', data: { isOpen: false, message: 'Outer Tooltip' } })
 body { font-family: sans-serif; margin: 42px; } .tooltip { display: block !important; z-index: 10000; } .tooltip .tooltip-inner { background: black; color: white; border-radius: 16px; padding: 5px 10px 4px; } .tooltip .tooltip-arrow { width: 0; height: 0; border-style: solid; position: absolute; margin: 5px; border-color: black; } .tooltip[x-placement^="top"] { margin-bottom: 5px; } .tooltip[x-placement^="top"] .tooltip-arrow { border-width: 5px 5px 0 5px; border-left-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; bottom: -5px; left: calc(50% - 5px); margin-top: 0; margin-bottom: 0; } .tooltip[x-placement^="bottom"] { margin-top: 5px; } .tooltip[x-placement^="bottom"] .tooltip-arrow { border-width: 0 5px 5px 5px; border-left-color: transparent !important; border-right-color: transparent !important; border-top-color: transparent !important; top: -5px; left: calc(50% - 5px); margin-top: 0; margin-bottom: 0; } .tooltip[x-placement^="right"] { margin-left: 5px; } .tooltip[x-placement^="right"] .tooltip-arrow { border-width: 5px 5px 5px 0; border-left-color: transparent !important; border-top-color: transparent !important; border-bottom-color: transparent !important; left: -5px; top: calc(50% - 5px); margin-left: 0; margin-right: 0; } .tooltip[x-placement^="left"] { margin-right: 5px; } .tooltip[x-placement^="left"] .tooltip-arrow { border-width: 5px 0 5px 5px; border-top-color: transparent !important; border-right-color: transparent !important; border-bottom-color: transparent !important; right: -5px; top: calc(50% - 5px); margin-left: 0; margin-right: 0; } .tooltip[aria-hidden='true'] { visibility: hidden; opacity: 0; transition: opacity .15s, visibility .15s; } .tooltip[aria-hidden='false'] { visibility: visible; opacity: 1; transition: opacity .15s; } .box { border: 1px solid red; border-radius: 2px; padding: 15px; margin: 20px; text-align: center; cursor: pointer; } .box:hover { box-shadow: 0 0 4px; }
 <script src="https://unpkg.com/popper.js"></script> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/v-tooltip"></script> <div id="app"> <div v-tooltip="{content: message, show: isOpen}" class="box" @mouseover.stop="isOpen=true"> {{ message }} <div v-tooltip="'Inner tooltip'" @mouseover.stop="isOpen=false" class="box"> okokok </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM