【问题标题】:How to disable b-tooltip auto position placement Bootstrap-Vue如何禁用 b-tooltip 自动位置放置 Bootstrap-Vue
【发布时间】:2021-09-27 07:41:47
【问题描述】:

我有一个工具提示,我希望它始终位于顶部和中心,即使顶部空间不足,调整大小时它也不会改变。我希望工具提示溢出到外面。但是当空间不够时它会自行改变位置

链接沙箱:https://codesandbox.io/s/tooltip-bootstrap-vue-8vjtl?file=/src/App.vue

   <div style="background: #ccc">
       <div id="tooltip_1" style="background: #fff"><div>
       <b-tooltip :target="tooltip_1" placement="top" fallback-placement="flip"   triggers="click blur">
         Text demodemo
       </b-tooltip>
    <div>

现在是这样的:

但我想要的是:

看起来它与fallback-placement 相关,但我不知道如何禁用它。

谢谢大家!

【问题讨论】:

标签: vue.js bootstrap-4 bootstrap-vue


【解决方案1】:

试试下面的代码。 Sandbox Example

方法一:需要加boundary="document"

<template>
  <div id="app">
    <div class="wrap">
      <div class="box">
        <div
          class="item"
          id="tooltip-target-1"
          :style="{ width: sizeWidth + 'px' }"
        >
          Click me
          <b-tooltip target="tooltip-target-1" triggers="click" placement="top"
          boundary="document">
            <span class="bold">I want it</span><br />
            <span>break the line</span><br />
            <span class="yellow">and custom style</span>
          </b-tooltip>
        </div>
        <button @click="zooOut">Zoom</button>
      </div>
    </div>
  </div>
</template>

方法二:

<template>
  <div id="app">
    <div class="wrap">
      <div class="box">
        <div
          class="item"
          v-b-tooltip.click.top.html="toolTipData"
          id="tooltip-target-1"
        >
          Click me
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      toolTipData: {
        title: `<span class="bold">I want it</span><br /><span>break the line</span><br /><span class="yellow">and custom style</span>`,
      },
    };
  },
};
</script>

【讨论】:

  • 谢谢!但我还有一个问题,当元素改变宽度时,工具提示如何始终在元素中间移动?请帮助我codesandbox.io/s/tooltip-bootstrap-vue-forked-1028s?file=/src/…
  • 在您的沙箱中,它始终在元素中间打开,增加宽度后,只需再次单击Click Me 按钮。一旦您注意到这一点,并且如果这有助于将其标记为答案,那么它对其他人也有帮助。
  • 我不想再次点击,我希望它是自动的,因为这是一个简单的例子,但我正在开发一个有数百个工具提示的系统,这些工具提示无法单击以更改每一个.但你回答了我的主要问题,所以我会将其标记为有帮助。
  • 我不认为我们可以自动实现它,因为工具提示的位置是在渲染时确定的。
  • 我得到了解决方案,将boundary="document"添加到b-tooltip标签
猜你喜欢
  • 2020-12-17
  • 2018-10-04
  • 2018-12-09
  • 1970-01-01
  • 1970-01-01
  • 2020-08-19
  • 2023-04-01
  • 1970-01-01
  • 2019-02-19
相关资源
最近更新 更多