当前位置: 首页 > news >正文

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

//鼠标悬浮效果
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 hotspotsthis.currentTaskIndex = index;this.currentTask = this.tasks[index];this.currentHotspots = this.currentTask.hotspots;},previousTask() {// Display previous taskif (this.currentTaskIndex > 0) {this.setCurrentTask(this.currentTaskIndex - 1);}},nextTask() {// Display next taskif (this.currentTaskIndex < this.tasks.length - 1) {this.setCurrentTask(this.currentTaskIndex + 1);}},handleClick(area) {// Handle click event for hotspotconsole.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 hotspotsthis.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.lryc.cn/news/323335.html

相关文章:

  • 靠谱!朋友圈一键转发和自动转发好友朋友圈
  • 线性顺序表算法库
  • java分割等和子集(力扣Leetcode416)
  • 383. 赎金信
  • 【二】【单片机】有关独立按键的实验
  • AJAX踩坑指南(知识点补充)
  • 备战蓝桥杯Day29 - 拼接最大数字问题
  • 基于springboot的mysql实现读写分离
  • Python爬虫之Scrapy框架系列(24)——分布式爬虫scrapy_redis完整实战【XXTop250完整爬取】
  • 提升效率,稳定可靠:亚信安慧AntDB的企业价值
  • 洛谷入门——P1567 统计天数
  • C++概述
  • Linux学习笔记16 - 系统命令
  • 读书笔记--阅读华为数据治理之旅有感
  • 网络安全协议基本问题
  • 面试(一)
  • libVLC windows开发环境搭建
  • 【Netty】Netty的使用和常用组件详解
  • Legacy|电脑Windows系统如何迁移到新安装的硬盘?系统迁移详细教程!
  • Windows 11 安装 Scoop
  • 新能源汽车小三电系统
  • 面试问答示范
  • 嵌入式3-22
  • JAVA Synchronized对象锁和类锁区别(牛逼)
  • 力扣算法题之好数对的数目
  • C++ vector 删除
  • ASP.NET-WebFoms常见前后端交互方式
  • LWC 学习资源
  • Debezium日常分享系列之:Debezium2.5稳定版本之数据类型映射
  • 通过JWT完成token登录验证