当鼠标悬停在网页上的文本上时突出显示映射图像的部分

发布于 2024-08-13 14:25:15 字数 316 浏览 8 评论 0原文

场景:

  • 映射了多个区域的图像。
  • 页面上的文本列表

所需的功能:当我将鼠标悬停在列表中的不同文本片段上时,映射图像中的相应区域将突出显示。

有谁知道有一个好的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

或十年 2024-08-20 14:25:15

我查看了您提到的插件的源代码,扩展它应该相当容易,以便它可以完成您想要它做的事情,这里有一些提示:

jquery.maphighlight.js 的第 127-136 行:

mouseover = function(e) {
   var shape = shape_from_area(this);
   add_shape_to(canvas, shape[0], shape[1], $.metadata ? $.extend({}, options, $(this).metadata()) : options);
};

if(options.alwaysOn) {
   $(map).find('area[coords]').each(mouseover);
} else {
   $(map).find('area[coords]').mouseover(mouseover).mouseout(function(e) { clear_canvas(canvas); });
}

这是所有事件魔法发生的地方。鼠标悬停功能用于突出显示一个区域。\

在您的代码中,您可以尝试通过执行以下操作来查找要突出显示的区域坐标:

$(map).find('#id_of_the_area[coords]').each(moseover);

其中 id_of_the_area 将是您为 < code>

要突出显示的标记。

如果将其放入函数中,您可以从任何需要的地方调用它。

编辑:

根据您在评论中的问题,这里有一些更多提示:

突出显示/取消突出显示某个区域的函数可能如下所示:

function highlight(e) {
   $(map).find('#id_of_the_area[coords]').each(moseover);
} 
function unHighlight(e) {
   clear_canvas($(canvas));
} 

在此示例中 id_of_map 和 < code>id_of_canvas 将是地图和画布元素的 id。

mouseoverclear_canvas 函数以及 mapcanvas 变量的范围可能是一个问题。您需要小心放置此代码的位置。我建议您在尝试添加此功能之前先阅读一下 jquery 插件。

在 jquery 中,您可以将事件附加到任何 html 元素。像这样:

$('#id_of_element').mouseover(highlight); 
$('#id_of_element').mouseout(unHighlight);

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:

mouseover = function(e) {
   var shape = shape_from_area(this);
   add_shape_to(canvas, shape[0], shape[1], $.metadata ? $.extend({}, options, $(this).metadata()) : options);
};

if(options.alwaysOn) {
   $(map).find('area[coords]').each(mouseover);
} else {
   $(map).find('area[coords]').mouseover(mouseover).mouseout(function(e) { clear_canvas(canvas); });
}

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:

$(map).find('#id_of_the_area[coords]').each(moseover);

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:

function highlight(e) {
   $(map).find('#id_of_the_area[coords]').each(moseover);
} 
function unHighlight(e) {
   clear_canvas($(canvas));
} 

In this example id_of_map and id_of_canvas would be the id of the map and canvas elements.

The scope of the mouseover or clear_canvas functions and map or canvas 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').mouseover(highlight); 
$('#id_of_element').mouseout(unHighlight);

id_of_element would be the id of the element that you would like to trigger the highlighting.

Hope this helps!

韬韬不绝 2024-08-20 14:25:15

虽然这不是超级优雅,但您可以手动触发相关区域元素的 mouseover 事件:

<a href="..." onmouseover="$('#certain-area')
       .trigger('mouseover');">link text</a>

对于 mouseout 也是如此。当然,这比使用 onmousoveronmouseout 更好。

while this is not super-elegant, you can trigger the mouseover event of the area element in question manually:

<a href="..." onmouseover="$('#certain-area')
       .trigger('mouseover');">link text</a>

Same holds for mouseout. Of course, this is better done unobtrusively than using onmousover and onmouseout.

抹茶夏天i‖ 2024-08-20 14:25:15

Highslide 并不完全符合您的要求,但值得一看。

Highslide is not exactly what you asked for, but worth a look.

那小子欠揍 2024-08-20 14:25:15

函数打开(){

        var data = $('#test').mouseout().data('maphilight') || {};
        data.alwaysOn = !data.alwaysOn;
        $('#test').data('maphilight', data).trigger('alwaysOn.maphilight');
        $(".p-hover-new").css({
  "opacity": "1"
})

function TurnOn(){

        var data = $('#test').mouseout().data('maphilight') || {};
        data.alwaysOn = !data.alwaysOn;
        $('#test').data('maphilight', data).trigger('alwaysOn.maphilight');
        $(".p-hover-new").css({
  "opacity": "1"
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文