javascript - 如何使用 AngularJS 在部分 html 文件中悬停时突出显示图像图中的区域

标签 javascript jquery html angularjs

我已经使用 AngularJS 设置了一个单页 Web 应用程序,在我的一个部分中,我有一个图像映射,并想在鼠标悬停时突出显示这些区域。我试着四处寻找,试图弄清楚如何做到这一点,但我不确定出了什么问题。这是代码。

我尝试使用 https://github.com/cowglow/AngularJS-maphilights作为资源

<section class="artistinfo">
 <div class="artist cf">
<h1>Select a room for more details</h1>
<div class="info">
  <img ng-src="images/housediagram.jpg" alt="Photo of thing" class="map" usemap="#houseMap">
  <map name="houseMap" id="Map" class="maphilight">
    <area name="kitchen" shape="poly" coords="197,193,348,194,349,301,197,302" href="#/kitchen"/>
    <area name="livingroom" shape="poly" coords="349,194,349,300,562,301,561,192" href="#/livingroom"/>
    <area name="laundry" shape="poly" coords="389,309,390,399,562,399,563,308" href="#/laundry"/>
    <area name="basement" shape="poly" coords="387,309,388,399,197,399,197,306" href="#/basement"/>
    <area name="office" shape="poly" coords="198,108,196,190,301,191,301,83,256,80" href="#/office"/>
    <area name="bathroom" shape="poly" coords="301,83,302,190,418,191,417,83" href="#/bathroom"/>
    <area name="bedroom" shape="poly" coords="419,83,417,192,560,191,560,109,494,80" href="#/bedroom"/>
  </map>

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>

  <script type="text/javascript" src="angular-maphilights.js"></script>

  <script type="text/javascript" charset="utf-8">
    angular.module('map', ['maphilights']);

  </script>
</div>

最佳答案

您必须编辑他的代码,因为他实际上并没有调用执行突出显示的 jQuery 函数。您可以将链接功能替换为以下内容

link: function (scope, element, attr) {
            $(element).load(function () {
                $(element).maphilight();
            }).trigger('load');
        }

此外,请务必在 <img> 上应用您的指令标签,而不是 <map>标签。

关于javascript - 如何使用 AngularJS 在部分 html 文件中悬停时突出显示图像图中的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30987682/

相关文章:

javascript - 在 JS 中组合关联数组/对象而不删除数字索引值 $.extend()

javascript - 将相同的值发送到另一个变量?

javascript - 将 "include"用于 HTML 代码时,边栏菜单不起作用

javascript - HTML 特殊字符在 js 中显示不正确

javascript - Handlebars 动态内联部分

javascript - 动态内容更改后 jQM 1.4.2 可折叠集无法正确刷新

javascript - 如何更快地加载通过ajax获取的数据?

javascript - 初学者 : Ajax tutorial is not working

javascript - 从函数返回时,for 循环未定义

html - 无法调整 div 中的表格大小