vue鼠标悬停出现悬浮框(简易版实现)

使用一个变量来控制悬浮框显示和隐藏,注意:这是简易版实现,其他功能需自行开发;

代码如下:

<template>
  <div>

    <div class="hover_wrapper">
        <div class="hover_text">划过显示</div>
        <div @mouseover="showHover=true" @mouseout="showHover=false" class="btn"><div class="hover_container" v-if="showHover">
                显示内容
            </div>
        </div>
    </div>
    
  </div>
</template>

<script>
export default {
  name: "ShowHover",
  component: {},
  data() {
    return {
      showHover: false
    };
  },
  methods: {},
  created() {},
};
</script>

<style lang="scss" scoped>

.hover_wrapper{
    position: relative;
    display: flex;
    .hover_text{
        width: 100px;
        height: 24px;
        text-align: center;
        line-height: 24px;
    }
    .btn{
        width: 24px;
        height: 24px;
        border: 1px solid #ccc;
        border-radius: 50%;
        text-align: center;
        line-height: 22px;
        position: relative;
        cursor: pointer;
    }
    .hover_container{
        width: 100px;
        height: 100px;
        border: 1px solid #ccc;
        border-radius: 8px;
        text-align: center;
        line-height: 98px;
        position: absolute;
        left: 50px;
        top: 50%;
        z-index: 99;
        transform: translateY(-50%);
    }
}

</style>

效果如下:
在这里插入图片描述
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐