【问题标题】:How can i close the vue popover when i scroll the screen滚动屏幕时如何关闭vue弹出窗口
【发布时间】:2021-04-22 04:33:46
【问题描述】:

我还没有为 Vue 决定任何弹出框。 设备是触控设备 对于触摸设备,我需要单击事件来打开弹出框。 设想: 我使用了 Vue 引导弹出框或工具提示 当我滚动时它卡在屏幕上。 滚动时需要删除

【问题讨论】:

    标签: vue.js bootstrap-4 vuejs2 touch-event bootstrap-vue


    【解决方案1】:

    你可以使用这个sn-p:

    new Vue({
      el: "#app",
      methods: {
        do_sth() {
          this.$root.$emit('bv::hide::popover')
        }
      },
      created () {
          window.addEventListener('scroll', this.do_sth);
      },
    });
    body .wrapper {
        padding: 100px 20px;
        min-height: 2000px;
    }
    <link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap@4.5.3/dist/css/bootstrap.min.css" />
    
    <script src="https://unpkg.com/vue@2.6.12/dist/vue.min.js"></script>
    <script src="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.min.js"></script>
    
    
    <div id="app">
    <div class="wrapper">
    <b-button
      href="#"
      tabindex="0"
      v-b-popover.click="'Popover content'"
      title="Popover title"
    >
      Link button with popover directive
    </b-button>
    
    </div>
    
    </div>

    【讨论】:

    • 如果滚动在div中
    • 是的,您可以使用查询选择器,例如:document.getElementById('your-div-id').addEventListener('scroll', this.do_sth)
    • 欢迎您,如果对您有帮助,请考虑接受。
    • 如果有很多弹出框并且我想切换该弹出框怎么办。我正在使用 v-b-popover 术语
    • 因为我使用 v-b-popover.hover 因为我希望它也可以在桌面和触摸设备上工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多