为什么maphilight库不使用图像映射和handlebar.js

时间:2017-07-29 10:03:35

标签: javascript jquery imagemap maphilight

这是我的小提琴。 https://jsfiddle.net/vsjtfhkk/

$(function() {
  $('img[usemap]').maphilight()
});

// Define our data object
var context = {
  "url": "http://1jpg-site.orionhub.org:8000/1.jpg",
  "class": "img-responsive center-block map",
  "map": [{
    "shape": "rect",
    "coords": "2,1,106,116",
    "function": "article1()"
  }, {
    "shape": "rect",
    "coords": "111,2,464,114"
  }, {
    "shape": "rect",
    "coords": "476,9,586,116"
  }, {
    "shape": "rect",
    "coords": "4,118,588,136"
  }, {
    "shape": "poly",
    "coords": "3,143,588,143,585,442,354,447,347,338,0,336"
  }, {
    "shape": "rect",
    "coords": "2,340,351,503"
  }, {
    "shape": "rect",
    "coords": "3,508,352,735"
  }, {
    "shape": "rect",
    "coords": "354,450,588,733"
  }]
};
var context1 = {
  "url": "paper\\pages\\17062016\\2.jpg",
  "class": "img-responsive center-block map",
  "map": [{
    "shape": "rect",
    "coords": "2,1,106,116"
  }, {
    "shape": "rect",
    "coords": "111,2,464,114"
  }, {
    "shape": "rect",
    "coords": "476,9,586,116"
  }, {
    "shape": "rect",
    "coords": "4,118,588,136"
  }, {
    "shape": "poly",
    "coords": "3,143,588,143,585,442,354,447,347,338,0,336"
  }, {
    "shape": "rect",
    "coords": "2,340,351,503"
  }, {
    "shape": "rect",
    "coords": "3,508,352,735"
  }, {
    "shape": "rect",
    "coords": "354,450,588,733"
  }]
};

function page1() {
  var source = $("#image-template").html();
  var template = Handlebars.compile(source);
  // Pass our data to the template
  var theCompiledHtml = template(context);

  // Add the compiled html to the page
  $('.content-placeholder').html(theCompiledHtml);
}

function page2() {
  var source = $("#image-template").html();
  var template = Handlebars.compile(source);
  // Pass our data to the template
  var theCompiledHtml = template(context1);

  // Add the compiled html to the page
  $('.content-placeholder').html(theCompiledHtml);
}

function article1() {
  alert("yes i am passed");
}

我正在尝试使用图片和图片地图制作一个eNewsPaper网站。

当我使用maphilight库突出显示handlebar.js的图像地图时,它无法正常工作。

我正在尝试使用:

$('.map').maphilight();

请给我一个解决方案。

1 个答案:

答案 0 :(得分:0)

因为没有人回答我的问题,我自己已经解决了。我犯了一个愚蠢的错误,我必须使用

.maphilight();
函数范围内的

函数。 这是使用它的正确方法

function page1() {
    var source = $("#image-template").html();
    var template = Handlebars.compile(source);
    // Pass our data to the template
    var theCompiledHtml = template(context);

    // Add the compiled html to the page
    $('.content-placeholder').html(theCompiledHtml);
    $('.map').maphilight();
    $('#prev').addClass("disabled");
    $('#prev').removeClass("active");
    $('#2').removeClass("active");
    $('#3').removeClass("active");
    $('#next').removeClass("active");
    $('#1').addClass("active");


}

不是这个。

$(function() {
  $('img[usemap]').maphilight()
});

感谢@jwpfox编辑问题。