【发布时间】:2010-09-25 18:43:45
【问题描述】:
使用 Raphael,当您将鼠标悬停在形状附近的不可见区域上时,我试图让该形状出现。以下代码不起作用 - 我哪里出错了?
每个形状都有两条与之关联的 Raphael 路径:一条用于可见形状,另一条用于不可见区域。
<script type="text/javascript" charset="utf-8">
$("document").ready(function() {
var RM = Raphael("canvas", 1000, 500);
var attr = { // for the visible shapes
fill: "#bbb", "fill-opacity": 1,
stroke: "#222", "stroke-width": 0.3,
};
var attr2 = { // for the invisible hovering areas
fill: "green", "fill-opacity": 0.0,
stroke: "red", "stroke-width": 0,
};
var things = {};
/* Square */ things.square = [ RM.path("m 154.21525,71.431259 74.32805,0 0,70.496711 -74.32805,0 0,-70.496711 z").attr(attr),
RM.path("m 271.25132,77.933263 58.07304,0 0,56.409037 -58.07304,0 0,-56.409037 z").attr(attr2) ];
/* Triangle */ things.triangle = [ RM.path("m 154.02932,222.44063 36.78089,-58.23641 34.48208,58.2364 -71.26297,1e-5").attr(attr),
RM.path("m 271.25132,165.71032 58.07304,0 0,56.40903 -58.07304,0 0,-56.40903 z").attr(attr2) ];
for (var shape in things) {
shape[0].color = Raphael.getColor();
shape[1].onmouseover = function () {
shape[0].animate({fill:shape[0].color, stroke:"#ccc"}, 500);
document.getElementById(shape)[0].style.display = "block";
shape[0].toFront(); R.safari();
};
shape[1].onmouseout = function () {
shape[0].animate({fill:"#bbb", stroke:"#222"}, 500);
document.getElementById(shape)[0].style.display = "none";
shape[0].toFront(); R.safari();
};
} // end for every member of things
}); // end the document ready function
</script>
Raphael 网站上的示例使用了更复杂的 javascript: http://raphaeljs.com/australia.html
我没有使用这段代码,因为我不明白他们使用的函数语法:
(function (a, b) {
----
})(c, d);
但我仍然看不出我的版本有什么问题。
【问题讨论】:
标签: javascript arrays hover raphael