javascript - 如何在地图(html)坐标上设置图像或颜色?
问题描述
我试图在地图坐标中使用颜色而不是透明的可点击空间。当我单击圆圈(我只使用圆圈)时,颜色应该会改变(例如从红色变为蓝色)。
我尝试过使用背景颜色,但这不起作用,我认为正确的方法是使用 javascript 或 jquery。
<img src="mapworld.jpg" width="600" height="400" alt="mapworld" usemap="#mapworld">
<map name = "mapworld">
<area id = "s1" target="_blank" alt="Circle1" title="Position 1"
href="www.google.com.ec" coords="10, 20, 4" shape="circle">
</map>
解决方案
在做了一些研究之后,我发现了这个 JQuery 库,它可以自动处理突出显示区域,你所要做的就是.maphilight()
在你的图像上document
调用ready
.
您需要在 html 文件中下载并实现这两个文件:
jQuery:https ://code.jquery.com/jquery-3.3.1.min.js
这个必须在一个单独的文件中并包含在之后 JQuery
(在您的 html 文件 ofc 中)。
MapHighlight 库: https ://raw.githubusercontent.com/kemayo/maphilight/master/jquery.maphilight.js
这是一个展示演示的 JSFiddle:http: //jsfiddle.net/8Lw7saf6/1/
用法:
/* JQUERY */
$(document).ready(function(){
$('img[usemap]').maphilight();
});
这是文档中的两个演示:
https ://davidlynch.org/projects/maphilight/docs/demo_usa.html
https://davidlynch.org/projects/maphilight/docs/demo_world.html
推荐阅读
- mysql - MySQL:删除用户删除特定表的权限
- ios - 从 SwiftUI 导航到 UIViewController
- go - 使用反射获取指针接收器的 go-gin 的 handlerFunc
- sql-server - 原因:找不到与提供的名称匹配的登录名
- git - 从一个 git 迁移到另一个 git 的工具
- excel - Excel中的多个条件和多个解决方案
- python - Python Logistic Regression 中的 scikit-learn 出现巨大而奇怪的错误?
- c# - INotifyPropertyChanged 通过间接层改变
- strapi - 使用 Strapi 推送通知
- javascript - 使用 Node.js 驱动程序连接到 MongoDB Atlas 集群时出错