優れたjavascriptライブラリRaphaelと一緒に使用するために、ニュージーランドのSVGマップを作成しましたが、不幸にもバグや構文上の違いがあると思いますIEのjavascriptインタープリタ。Firefox/Chromeで動作しているのにIEで失敗する
Firefoxや他のブラウザでは、onlickイベントとonmouseoverイベントは完全に機能しますが、IEでは起動しません(IE 7でテスト済み)。残念ながら、これをデバッグするのに役立つjavascriptエラーはないので、私はIEがこれらのイベントを根本的に異なる方法で処理すると仮定することができます。
<script type="text/javascript" charset="utf-8">
window.onload = function() {
var R = Raphael("paper", 450, 600);
var attr = {
fill: "#3f3f40",
stroke: "#666",
"stroke-width": 1,
"stroke-linejoin": "round"
};
var nz = {};
nz.northland = R.path(attr, "M 193.34222,3.7847503 C 194.65463");
// SVG data stripped for sake of brevity
var current = null;
for (var region in nz) {
nz[region].color = Raphael.getColor();
(function(rg, region) {
rg[0].style.cursor = "pointer";
rg[0].onmouseover = function() {
current && nz[current].animate({ fill: "#3f3f40", stroke: "#666" }, 500) && (document.getElementById(current).style.display = "");
rg.animate({ fill: rg.color, stroke: "#ccc" }, 500);
rg.toFront();
R.safari();
document.getElementById(region).style.display = "block";
current = region;
};
rg[0].onclick = function() {
alert("IE never gets this far.");
//window.location.href = "my-page.aspx?District=" + region;
};
rg[0].onmouseout = function() {
rg.animate({ fill: "#3f3f40", stroke: "#666" }, 500);
};
if (region == "northland") {
rg[0].onmouseover();
}
})(nz[region], region);
}
};
</script>
多くの感謝:)
jQuery、dojo、mootools、prototype/scriptaculousなど、クロスブラウザーの問題を解決したフレームワークを採用するだけで、このような問題を避けることができます。 – tvanfosson
良い提案 - 明らかに私のjquery-fuを改善する良い時期です。ありがとう:) –
それはより具体的なケースです:あなたはSVG要素のイベントサポートを見ています。これは、標準的なHTML要素に対するクロスブラウザーイベントのサポートと同じではありません。 IEがSVG要素のmousedownとmouseupイベントをサポートしていないことは、(私が確認していない)場合があります。 –