【问题标题】:Imagemap on hover display image悬停显示图像上的图像映射
【发布时间】:2023-04-10 07:17:01
【问题描述】:

我已经为我正在开发的网站创建了一个图像地图,我知道这有点老派,但我被明确要求实现需要这种类型的东西。

本质上,当您将鼠标悬停在已指定的某些坐标上时,我希望将图像显示为悬停项。我读过的大多数文档/问题都与大纲悬停有关,即映射区域将突出显示。我正在使用一个 Jquery 插件,它允许在保留正确坐标的同时调整图像大小,所以我没有使用任何其他通常允许在悬停时突出显示轮廓的其他插件。

我知道您可以使用 a:hover 等更改基本 html/css 中某些项目的属性,但是由于图像映射的性质,我认为这不是类似的情况。将鼠标悬停/单击图像地图上的指定区域时是否可以简单地显示图像?

我还研究了使用 Photoswipe(我已在单独页面的画廊中实现)以允许用户单击指定区域并显示 Photoswipe UI。如果可能的话,这将是更可取的,因为用户界面更时尚,字幕更容易。

图像映射代码:

<div class="sitebox">
<img name="aerialmap" src="images/aerial2.jpg" width="70%" usemap="#aerial2" style="border:5px solid #535353;">
    <map name="aerial2">
        <area shape="poly" coords="531,287,538,321,610,301,601,270" href="#" onclick="return false" title="building 1">
        <area shape="poly" coords="196,246,240,255,213,384,166,376" href="#" onclick="return false" title="Building 2">
    </map>

图像地图调整器:

https://github.com/davidjbradshaw/image-map-resizer

如果需要更多代码来了解我目前已实现的功能,我会提供。

【问题讨论】:

    标签: jquery css hover imagemap photoswipe


    【解决方案1】:

    我想这就是你需要的

    $("area").mousemove(function(e) {
        $("#image").show().css({
            left: e.pageX + 10,
            top: e.pageY + 10
        });
    });
    $("area").mouseout(function(e) {
        $("#image").hide();
    });
    #image{
    position:absolute;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <div class="sitebox">
        <img name="aerialmap" src="http://www.getmapping.com/sites/default/files/styles/post_image/public/quick_media/getmapping_aerialimagery_vertical_hamptoncourt_1_0.jpg?itok=tNmyWk21" width="70%" usemap="#aerial2" style="border:5px solid #535353;">
        <map name="aerial2">
            <area shape="poly" coords="531,287,538,321,610,301,601,270" href="#" onclick="return false" title="building 1">
            <area shape="poly" coords="196,246,240,255,213,384,166,376" href="#" onclick="return false" title="Building 2">
        </map>
    </div>
    <img id="image" src="http://images.pictureshunt.com/pics/m/mouse-8557.JPG" />

    编辑

    这是一个fiddle,每个area 使用不同的图像。每个区域都有一个data-image 属性指向相关的图片网址。

    https://jsfiddle.net/ergec/gse19j0b/

    【讨论】:

    • 似乎这样可行,但我需要多个图像,具体取决于悬停的坐标。这很容易做到吗?
    • @Randorile 更新了我的答案。检查我答案最底部的小提琴。
    • 完美,感谢您的帮助。我想我会使用悬停/单击的某种组合来访问完整图像,并简单地使用悬停来按名称识别。
    【解决方案2】:
    <script>
        function MO(x){
            document.getElementById("a").innerHTML=x=='ov'?"<img src=\"http://www.w3schools.com/jsref/smiley.gif\"></img>":"";
        }
    </script>
    <div class="sitebox">
    <img name="aerialmap" src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Lion_waiting_in_Namibia.jpg/290px-Lion_waiting_in_Namibia.jpg" width="70%" usemap="#aerial2" style="border:5px solid #535353;">
    <map name="aerial2">
        <area shape="poly" coords="531,287,538,321,610,301,601,270" href="#" onclick="return false" title="building 1">
        <area shape="poly" coords="196,246,240,255,213,384,166,376" href="#" onclick="return false" border="2" title="Building 2" onmouseover="MO('ov')" onmouseout="MO('ou')">
    </map>
    </img></div>
    <div  id="a"></div>
    

    这有帮助吗?

    【讨论】:

    • 谢谢各位,离开几天了,让我测试一下,我会回复你的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 2014-01-21
    • 1970-01-01
    相关资源
    最近更新 更多