Vue+jquery+jquery.maphilight实现图片热区高亮以及点击效果

news/2024/7/11 1:04:16 标签: vue.js, jquery, 前端
//鼠标悬浮效果
mounted() {
  this.setCurrentTask(0);
//对于id为mapAll的热区图,设置鼠标放置在上面有一个颜色 fillColor填充颜色 strokeColor边框颜色 strokeWidth边框宽度 fillOpacity 是设置热区填充颜色的不透明度的属性。 alwaysOn:true 保持常量
  $(function() {
    $('#mapAll').maphilight({
      fillColor: 'ff0000',
      strokeColor: "FFFFFF",
      strokeWidth: 3,
      fillOpacity: 0.6,
    });
  });
},
//点击效果
handleHighlight(id) {
  const escapedId = id;
  const $element = $(`#${escapedId}`);
  const data = $element.mouseout().data('maphilight') || {};
  data.alwaysOn = true;
  data.fillColor = "feeeed";
  $element.data('maphilight', data).trigger('alwaysOn.maphilight');
  setTimeout(() => {
    const data = $element.mouseout().data('maphilight') || {};
    data.fillColor = "ff0000";
    data.alwaysOn = false;
    $element.data('maphilight', data).trigger('alwaysOn.maphilight');
  }, 300);
},

好的设计思路:

​
<template>
  <div>
    <!-- Task Display -->
    <div>
      <h2>Task {{ currentTask.id }}: {{ currentTask.name }}</h2>
      <p>{{ currentTask.details }}</p>
      <img ref="mapAll" id="mapAll" src="../../assets/images/JIESHOUJI.png" usemap="#image-map">
      <map v-if="currentHotspots" name="image-map">
        <area v-for="(area, index) in currentHotspots" :key="index" :id="area.id" :title="area.title" :coords="area.coords" :shape="area.shape" @click="handleClick(area)">
      </map>
    </div>

    <!-- Global Navigation Buttons -->
    <div>
      <button @click="previousTask" :disabled="currentTaskIndex === 0">Previous</button>
      <button @click="nextTask" :disabled="currentTaskIndex === tasks.length - 1">Next</button>
    </div>
  </div>
</template>

<script>
import $ from "jquery"
import 'jquery/dist/jquery.maphilight'

export default {
  data() {
    return {
      tasks: [
        {
          id: 1,
          name: '开始实验',
          details: '按On->显示自检->出现屏幕',
          hotspots: [
            { id: 1, alt: 'Power', title: 'Power', coords: '133,34,178,86', shape: 'rect' },
            { id: 2, alt: 'LockTest', title: 'LockTest', coords: '1059,150,1096,205', shape: 'rect' }
          ]
        }
        // Add more tasks here if needed
      ],
      currentTaskIndex: 0,
      currentTask: {},
      currentHotspots: []
    };
  },
  methods: {
    setCurrentTask(index) {
      // Set current task and associated hotspots
      this.currentTaskIndex = index;
      this.currentTask = this.tasks[index];
      this.currentHotspots = this.currentTask.hotspots;
    },
    previousTask() {
      // Display previous task
      if (this.currentTaskIndex > 0) {
        this.setCurrentTask(this.currentTaskIndex - 1);
      }
    },
    nextTask() {
      // Display next task
      if (this.currentTaskIndex < this.tasks.length - 1) {
        this.setCurrentTask(this.currentTaskIndex + 1);
      }
    },
    handleClick(area) {
      // Handle click event for hotspot
      console.log('Clicked hotspot:', area);
      this.handleHighlight(area.id)
      // Add your custom logic here
    },

    // maplight处理按钮特效
    handleHighlight(id) {
      const $element = $(`#${id}`);
      const data = $element.mouseout().data('maphilight') || {};
      data.alwaysOn = true;
      data.fillColor = "feeeed";
      $element.data('maphilight', data).trigger('alwaysOn.maphilight');
      // 使用 setTimeout 来延迟还原状态
      setTimeout(() => {
        const data = $element.mouseout().data('maphilight') || {};
        data.fillColor = "ff0000";
        data.alwaysOn = false;
        $element.data('maphilight', data).trigger('alwaysOn.maphilight');
      }, 300);
    },
  },
  mounted() {
    // Initialize current task and hotspots
    this.setCurrentTask(0);
    // 对于id为mapAll的热区图,设置鼠标放置在上面有一个颜色 fillColor填充颜色 strokeColor边框颜色 strokeWidth边框宽度 fillOpacity 是设置热区填充颜色的不透明度的属性。 alwaysOn:true 保持常量
    $(function() {
      $('#mapAll').maphilight({
        fillColor: 'ff0000',
        strokeColor: "FFFFFF",
        strokeWidth: 3,
        fillOpacity: 0.6,
      });
    });
  },
};
</script>

<style scoped>
/* Add styles for task layout */
</style>

​


http://www.niftyadmin.cn/n/5446579.html

相关文章

win10下自由切换多版本JDK操作

1.在window 系统变量 path路径追加%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; 2.下载多版本jdk zip文件解压到到C:\Program Files\Java\目录下 3.定义切换Java版本的bat文件,内容如下 @echo off @echo -------------------welcome to use Java version switch service------------…

QWebEngineView无法播放H5中的mp4

文章目录 一、问题二、原因三、解决办法一、问题 使用 pyqt、pyside 的 QWebEngineView 编写的浏览器无法播放html页面中的视频 二、原因 查阅资料后发现,对于视频是 m3u8 格式的文件 , QT 安装包自带的 QWebEngineView 是不支持在线解码的,所以播放不了,大致和 html5 视频…

是德科技N9020A信号分析仪

181/2461/8938产品概述&#xff1a; N9020A MXA信号分析仪通过增加针对新一代技术的信号分析和频谱分析能力&#xff0c;具备了中档分析仪的更高性能。它突破了以往分析仪的极限&#xff0c;支持业界更快的信号和频谱分析,实现了速度与性能的更佳优化。 速度 测试速度超过其它…

Oracle修改Number类型精度报错:ORA-01440

修改Number类型的字段的精度SQL ALTER TABLE XXXX MODIFY RATE NUMBER(30,6); 如果表已经存在数据&#xff0c;报错信息如下&#xff1a; ORA-01440: column to be modified must be empty to decrease precision or scale 废话不多说&#xff0c;解决方案如下&#xff1a;…

PLC常用通信协议应用

PLC通信协议 ModbusModbus协议介绍Modbus协议的应用Modbus通信模式 Modbus RTU通讯Modbus RTU报文映射寄存器常见功能码数据类型Modbus CRC校验计算Modbus RTU举例&#xff08;读位&#xff09;Modbus RTU举例&#xff08;读字&#xff09; Modbus TCP协议应用TCP数据帧Modbus …

物联网如何改善供应链的透明度和效率

物联网&#xff08;IoT&#xff09;技术通过将物理对象连接到互联网&#xff0c;使得它们能够收集和交换数据&#xff0c;从而为供应链管理带来了革命性的变化。物联网改善供应链透明度和效率的几个关键方式包括&#xff1a; 实时追踪和监控&#xff1a;物联网设备可以实时追踪…

openGauss学习笔记-249 openGauss性能调优-使用Plan Hint进行调优-Join顺序的Hint

文章目录 openGauss学习笔记-249 openGauss性能调优-使用Plan Hint进行调优-Join顺序的Hint249.1 功能描述249.2 语法格式249.3 参数说明249.4 示例 openGauss学习笔记-249 openGauss性能调优-使用Plan Hint进行调优-Join顺序的Hint 249.1 功能描述 指明join的顺序&#xff0…

外包干了6天,技术退步明显。。。。

说一下自己的情况&#xff0c;本科生&#xff0c;19年通过校招进入上海某软件公司&#xff0c;干了接近4年的功能测试&#xff0c;今年年初&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落!而我已经在一个企业干了四年的功能测试&a…