当鼠标悬停在网页上的文本上时突出显示映射图像的部分
场景:
- 映射了多个区域的图像。
- 页面上的文本列表
所需的功能:当我将鼠标悬停在列表中的不同文本片段上时,映射图像中的相应区域将突出显示。
有谁知道有一个好的 javascript 工具可以做到这一点吗?
我找到了一个 jquery 插件(地图高亮),它将突出显示图像的部分将鼠标移到图像本身上。我正在寻找下一步 - 从图像外部的源触发高光。
Scenario:
- Image with several areas mapped.
- A list of text on the page
Desired functionality: When I mouseover the different pieces of text in the list, corresponding areas in the mapped image will become highlighted.
Does anyone know of a good javascript tool that can do this?
I have found a jquery plugin (map hilight) that will highlight the section of the image as you move your mouse over the image itself. I am looking for the next step - triggering the highlights from a source outside of the image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我查看了您提到的插件的源代码,扩展它应该相当容易,以便它可以完成您想要它做的事情,这里有一些提示:
jquery.maphighlight.js 的第 127-136 行:
这是所有事件魔法发生的地方。鼠标悬停功能用于突出显示一个区域。\
在您的代码中,您可以尝试通过执行以下操作来查找要突出显示的区域坐标:
其中
要突出显示的标记。id_of_the_area
将是您为 < code>如果将其放入函数中,您可以从任何需要的地方调用它。
编辑:
根据您在评论中的问题,这里有一些更多提示:
突出显示/取消突出显示某个区域的函数可能如下所示:
在此示例中
id_of_map
和 < code>id_of_canvas 将是地图和画布元素的 id。mouseover
或clear_canvas
函数以及map
或canvas
变量的范围可能是一个问题。您需要小心放置此代码的位置。我建议您在尝试添加此功能之前先阅读一下 jquery 插件。在 jquery 中,您可以将事件附加到任何 html 元素。像这样:
id_of_element 将是您想要触发突出显示的元素的 id。
希望这有帮助!
I looked at the source code for the plugin you mentioned and it should be fairly easy to extend it so that it will do what you want it to do, here a few hints:
Line 127-136 of jquery.maphighlight.js:
This is where all the event magic happens. The mouseover function is used to highlight an area.\
In your code you could try to find the area coordinates you want to highlight by doing something like this:
Where
id_of_the_area
would be an id that you gave the<area>
tag that you want to highlight.If you put that into a function you can call that from wherever you need it from.
Edit:
Based on your question in the comment, here are some more pointers:
The functions to highlight/unhighlight an area could look something like this:
In this example
id_of_map
andid_of_canvas
would be the id of the map and canvas elements.The scope of the
mouseover
orclear_canvas
functions andmap
orcanvas
variables might be an issue there. You need to be careful on where to place this code. I'd suggest reading up on jquery plugins a bit before you try to add this functionality.In jquery you can attach events to any html element. Like this:
id_of_element would be the id of the element that you would like to trigger the highlighting.
Hope this helps!
虽然这不是超级优雅,但您可以手动触发相关区域元素的 mouseover 事件:
对于 mouseout 也是如此。当然,这比使用
onmousover
和onmouseout
更好。while this is not super-elegant, you can trigger the mouseover event of the area element in question manually:
Same holds for mouseout. Of course, this is better done unobtrusively than using
onmousover
andonmouseout
.Highslide 并不完全符合您的要求,但值得一看。
Highslide is not exactly what you asked for, but worth a look.
函数打开(){
function TurnOn(){