2017-07-29 44 views
0

这是我的小提琴。 https://jsfiddle.net/vsjtfhkk/为什么maphilight库不能与图像映射和handlebar.js

$(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(); 

请给我一个解决方案。

回答

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编辑问题。

相关问题