我刚开始使用Raphael.js,我很难在路径中添加id.我已经阅读了很多关于如何做的帖子,但我认为我的文件设置方式不允许我轻松翻译这些解决方案.
我有一个init.js文件和一个path.js文件
init.js
var r = Raphael('man', 500, 573),
attributes = {
fill: '#204ad3',
opacity: '0.0',
'stroke-linejoin': 'round'
},
arr = new Array();
for (var muscles in paths) {
var obj = r.path(paths[muscles].path);
obj.attr(attributes);
arr[obj.id] = muscles;
obj
.hover(function(){
this.animate({
fill: '#204ad3',
opacity: '0.3'
}, 300);
}, function(){
this.animate({
fill: attributes.fill,
opacity: attributes.opacity
}, 300);
})
.click(function(){
document.location.hash = arr[this.id];
var point = this.getBBox(0);
$('#man').next('.point').remove();
$('#man').after($('<div />').addClass('point'));
$('.point')
.html(paths[arr[this.id]].name)
.prepend($('<a />').attr('href', '#').addClass('close').text('Close'))
.prepend($('<img />').attr('src', 'flags/'+arr[this.id]+'.png'))
.css({
left: point.x+(point.width/2)-80,
top: point.y+(point.height/2)-20 …Run Code Online (Sandbox Code Playgroud)