问题描述
我正在创造一个解剖学人,用户可以翻转肌肉,肌肉突出显示,点击时他们显示肌肉的名称。通过单独的JQuery,我有一组< dl>
,根据点击的肌肉群显示和隐藏。这在IE9和其他现代浏览器中工作正常,但我在IE8中遇到了问题。 IE8只想在生成的raphael.js中使用代码。所以我需要将jquery移动到raphael ......我相信这将是一种更优雅的方式。但是,我不确定如何继续这样做。
I am creating an anatomic man where the user can rollover muscles, the muscles are highlighted and when clicked they display the name of the muscle. Through a separate JQuery, I have a group of <dl>
s that show and hide depending on the muscle group clicked. This works fine in IE9, and other modern browsers, but I am having an issue within IE8. IE8 only wants to use the code within the generated raphael.js. So I need to move the jquery into raphael…which I'm sure will be a more elegant way of doing this. However, I am unsure of how to proceed with this.
这是我的代码:
paths.js
var paths = {
neck: {
name: 'neck',
path: 'd="M412.294,73.035c0,0,7.661,28.869,9.406,31.78c1.746,2.911,4.657,2.911,9.896,2.911 s9.313-1.746,9.896-5.239c0.582-3.493,6.985-28.523,6.985-28.523s-2.963,2.599-6.232,5.984c-2.543,2.632-7.2,5.904-11.088,5.904 c-3.889,0-6.705-2.431-10.367-5.04C418.063,78.868,418.08,79.22,412.294,73.035z"',
},
pecks: {
name: 'Pecks',
path: 'd="M379.581,117.994c0,0,0.396-1.586,6.936-4.558c6.539-2.972,13.475-5.351,16.844-6.737 c3.369-1.387,4.559-1.784,4.559-1.784s13.674,2.973,15.061,3.17c1.387,0.198,4.36,1.982,8.72,1.982s9.511-1.387,11.097-2.18 s10.307-2.973,11.693-3.171s1.387-0.198,1.387-0.198s12.286,3.369,16.845,4.36c4.558,0.991,8.917,2.378,9.116,3.765 c0.197,1.387,1.584,4.954,1.584,6.341s-0.197,5.945-0.396,6.738c-0.198,0.792-3.171,15.457-4.757,21.997 c-1.585,6.54-1.188,8.918-7.331,11.494s-10.899,7.53-22.79,2.378s-13.277-5.549-17.241-5.152s-11.098,3.963-14.862,5.351 c-3.766,1.387-16.251,2.179-20.412-0.198c-4.162-2.378-10.9-9.314-12.881-16.844c-1.981-7.531-3.963-16.052-4.359-17.638 C377.995,125.525,377.798,121.165,379.581,117.994z"',
},
}
init.js
$(function(){
var r = Raphael('man', 500, 573),
attributes = {
fill: '#204ad3',
opacity: '0.0',
'stroke-linejoin': 'round'
},
arr = new Array();
var id = 0;
for (var muscles in paths) {
var obj = r.path(paths[muscles].path);
obj.attr(attributes);
obj.node.id = "muscle" + id;
id++
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'))
.css({
left: point.x+(point.width/2)-80,
top: point.y+(point.height/2)-20
})
.fadeIn();
});
$('.point').find('.close').live('click', function(){
var t = $(this),
parent = t.parent('.point');
parent.fadeOut(function(){
parent.remove();
});
return false;
});
}
});
在init.js代码中有一个点击(function()
为肌肉组生成弹出窗口。如何根据用户点击的路径添加允许其他jquery发生的代码?如下所示:
In the init.js code there is a click(function()
that generates a popup for the muscle group. How could I add a code that would allow other jquery to happen depending on the path the user clicks? Something like:
$("dl").hide().delay(100);$('.tag-pathnamehere').show();
其中'pathnamehere'部分会根据所点击的路径而改变。
where 'pathnamehere' part of the class would change depending on the path clicked.
我相信这一行会为弹出窗口添加路径名称:
I believe this line adds the path name to the popup:
(paths[arr[this.id]].name)
我想以某种方式将类的'pathnamehere'部分更改为单击的路径。
I would like to somehow change the 'pathnamehere' part of the class to the path clicked.
我希望这很清楚,任何帮助都会非常感激。
I hope this is clear and any help would be much appreciated.
推荐答案
假设已经创建了 dl
元素(是吗?),我猜你可以这样做:
Assuming that the dl
elements are already created (are they?), I guess you could do something like:
arr = new Array();
tags = new Array();
...
arr[obj.id] = muscles;
tags[obj.id] = ".tag-" + paths[muscles].name;
然后在点击
处理程序
$(tags[this.id]).show();
这篇关于raphael.js IE8和Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!