joken-前端工程师

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::
  404 随笔 :: 39 文章 :: 8 评论 :: 20万 阅读

github地址

https://github.com/shadow-Fiend/hotspot-vue3

测试代码

<template>
  <div class="interactive-image">
    <hotspot :image="image" :zonesInit="zones" :types="types" :minSize="52" :switchOptions="{
      isShowSign: true,
      isShowDelete: true,
      isOverlap: false,
      isShowActive: true
    }" :styleOptions="{}" @add="handleAdd"></hotspot>
    <div class="interactive-image__controls">
      <button type="button" class="btn-primary" @click="handleAdd">添加热点</button>
      <div v-for="(zone, index) in zones" :key="index" class="input-group">
        <input type="text" v-model="zone.url" :placeholder="`区域 ${index + 1} 链接`" class="input-url" />
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import Hotspot from 'hotspot-vue3';

interface ZoneType {
  topPer: number;
  leftPer: number;
  widthPer: number;
  heightPer: number;
  url?: string;
  active?: boolean;
  key?: string;
}

export default defineComponent({
  name: 'InteractiveImage',
  components: {
    Hotspot,
  },
  setup() {
    const image = ref('https://preview.qiantucdn.com/58pic/71/00/18/53n58PICPnzmqGtYCyb5N_origin_PIC2018.jpg!qt_w320');
    const zones = ref<ZoneType[]>([]);
    const types = ref<'move' | 'btn'>('move');

    const handleAdd = (zon: ZoneType) => {
      let zone: ZoneType;
      if (zon.topPer) {
        zone = zon;
        zone.url = 'https://github.com';
        types.value = 'move';
      } else {
        zone = {
          heightPer: 0.2027,
          leftPer: 0.2027,
          topPer: 0.2027,
          widthPer: 0.1027,
          url: 'https://github.com',
          key: String(Math.random()),
        };
        types.value = 'btn';
      }
      zones.value.push(zone);
    };

    return {
      image,
      zones,
      types,
      handleAdd,
    };
  },
});
</script>

<style scoped>
.interactive-image {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 555px;
  min-width: 1000px;

  &__controls {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .btn-primary {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    margin-bottom: 10px;
  }

  .input-group {
    margin-bottom: 10px;
  }

  .input-url {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    width: 300px;
  }
}

:deep(img) {
  display: block !important;
}
</style>

代码运行效果

image

posted on   joken1310  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示