Raphaeljs 和 Internet Explorer,单击元素时出现问题
我有下面一段 JavaScript 代码,当我点击它时,它基本上隐藏或显示 Raphaeljs 集。它在 Google Chrome、FireFox 和 Safari 下运行得非常好,但在 Internet Explorer 下根本不行。
var paper = Raphael(document.getElementById('ADiv'), 450, 490);
var group = paper.set();
var toxicRect = paper.rect(0, 0, 120, 60, 10 );
toxicRect.attr({"stroke-width": 1,
"stroke" : "#3083BE",
"fill" : "#D1DFE9"});
group.push( toxicRect );
var toxicRectText = paper.text(60, 25, "Toxic in air\nthrough inhalation");
toxicRectText.attr({"font-size": 12 });
group.push( toxicRectText );
var toxicToConcentrationPath = paper.path("M60 60L60 80")
toxicToConcentrationPath.attr({"stroke-width": 1,
"stroke" : "#3083BE"});
group.push( toxicToConcentrationPath );
var concentrationRect = paper.rect(0, 80, 120, 60, 10 );
concentrationRect.attr({"stroke-width": 1,
"stroke" : "#3083BE",
"fill" : "#D1DFE9"});
group.push(concentrationRect);
var conRectText = paper.text( 60, 105, "Is concentration\n> TLV/TWA");
conRectText.attr({"font-size": 12});
group.push(conRectText);
var conRectTextYes = paper.text(50, 135, "Yes / ");
conRectTextYes.attr({"font-size": 12,
"font-style": "italic"});
group.push(conRectTextYes);
var conRectTextNo = paper.text(75, 135, "No");
conRectTextNo.attr({"font-size": 12,
"font-style": "italic"});
group.push(conRectTextNo);
var monitorConcentrationGroup = paper.set();
var monitorConcentrationRect = paper.rect(140, 95, 60, 30, 10 );
monitorConcentrationRect.attr({"stroke-width": 1,
"stroke" : "#3083BE",
"fill" : "#D1DFE9"});
monitorConcentrationGroup.push(monitorConcentrationRect);
var monitorConcentrationRectText = paper.text(170, 115, "Monitor");
monitorConcentrationRectText.attr({"font-size": 12});
monitorConcentrationGroup.push(monitorConcentrationRectText);
var concentrationToMonitorPath = paper.path("M120 110L140 110")
concentrationToMonitorPath.attr({"stroke-width": 1,
"stroke" : "#3083BE"});
monitorConcentrationGroup.push(concentrationToMonitorPath);
monitorConcentrationGroup.hide();
//Actions when clicking on decisions
conRectTextYes.node.onclick = function () {
monitorConcentrationGroup.hide();
};
conRectTextNo.node.onclick = function () {
monitorConcentrationGroup.show();
};
有人有什么想法吗?您可以在 http://raphaeljs.com/playground.html 上进行测试,方法是进行剪切和粘贴,然后省略脚本的第一行。单击“否”应该会出现一个框,至少在 Chrome 中是这样,但在 IE 中不会...
谢谢!
I have the following piece of code in javascript that basically hide or show a Raphaeljs set when I click on it. It works perfectly well under Google Chrome, FireFox and Safari, but not at all under Internet Explorer.
var paper = Raphael(document.getElementById('ADiv'), 450, 490);
var group = paper.set();
var toxicRect = paper.rect(0, 0, 120, 60, 10 );
toxicRect.attr({"stroke-width": 1,
"stroke" : "#3083BE",
"fill" : "#D1DFE9"});
group.push( toxicRect );
var toxicRectText = paper.text(60, 25, "Toxic in air\nthrough inhalation");
toxicRectText.attr({"font-size": 12 });
group.push( toxicRectText );
var toxicToConcentrationPath = paper.path("M60 60L60 80")
toxicToConcentrationPath.attr({"stroke-width": 1,
"stroke" : "#3083BE"});
group.push( toxicToConcentrationPath );
var concentrationRect = paper.rect(0, 80, 120, 60, 10 );
concentrationRect.attr({"stroke-width": 1,
"stroke" : "#3083BE",
"fill" : "#D1DFE9"});
group.push(concentrationRect);
var conRectText = paper.text( 60, 105, "Is concentration\n> TLV/TWA");
conRectText.attr({"font-size": 12});
group.push(conRectText);
var conRectTextYes = paper.text(50, 135, "Yes / ");
conRectTextYes.attr({"font-size": 12,
"font-style": "italic"});
group.push(conRectTextYes);
var conRectTextNo = paper.text(75, 135, "No");
conRectTextNo.attr({"font-size": 12,
"font-style": "italic"});
group.push(conRectTextNo);
var monitorConcentrationGroup = paper.set();
var monitorConcentrationRect = paper.rect(140, 95, 60, 30, 10 );
monitorConcentrationRect.attr({"stroke-width": 1,
"stroke" : "#3083BE",
"fill" : "#D1DFE9"});
monitorConcentrationGroup.push(monitorConcentrationRect);
var monitorConcentrationRectText = paper.text(170, 115, "Monitor");
monitorConcentrationRectText.attr({"font-size": 12});
monitorConcentrationGroup.push(monitorConcentrationRectText);
var concentrationToMonitorPath = paper.path("M120 110L140 110")
concentrationToMonitorPath.attr({"stroke-width": 1,
"stroke" : "#3083BE"});
monitorConcentrationGroup.push(concentrationToMonitorPath);
monitorConcentrationGroup.hide();
//Actions when clicking on decisions
conRectTextYes.node.onclick = function () {
monitorConcentrationGroup.hide();
};
conRectTextNo.node.onclick = function () {
monitorConcentrationGroup.show();
};
Anyone has any ideas? You can test it at http://raphaeljs.com/playground.html by making a cut and paste and omitting the first line of the script. Clicking the "No" should make a box appears, at least in Chrome, but not in IE...
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Raphael 使用 VML 在 IE8 中渲染形状,特别是示例中的 VML
textpath
元素。但是,IE8 不会触发该元素的鼠标事件。您可以沿着节点树向上并将事件处理程序附加到包含textpath
的shape
元素,但即使如此,活动区域也仅包含使文字向上,所以很难点击。更好的解决方案是在文本后面添加一个透明矩形,并将事件处理程序附加到该矩形:
工作演示:http://jsfiddle.net/brianpeiris/8CZ8G/show/(可通过以下方式编辑:http: //jsfiddle.net/brianpeiris/8CZ8G/)
Raphael uses VML to render shapes in IE8, specifically the VML
textpath
element in your example. However, IE8 does not fire mouse events for that element. You could go up the node tree and attach your event handler to theshape
element that contains thetextpath
but, even then, the active-area only consists of the pixels that make up the text, so it's very difficult to click.A better solution would be to add a transparent rectangle behind the text and attach your event handler to that as well:
Working Demo: http://jsfiddle.net/brianpeiris/8CZ8G/show/ (Editable via: http://jsfiddle.net/brianpeiris/8CZ8G/)
与另一个问题大致相似,我将发布相同的答案:
onmousedown 在 IE 7,8 和 9 中为我工作
我也尝试了一些其他方法,将函数抽象为变量,但它不起作用。就我而言,我无法在显示屏上添加一个矩形并让人们点击它,出于多种原因,这是一个糟糕的解决方案。
希望这有帮助!
roughly similar to another question and I will post the same answer:
onmousedown worked for me in IE 7,8, and 9
I tried some other methods as well, abstracting the function to a variable but it didnt work. In my case I cannot add a rectangle to the display and have people click on this, it was a poor solution for several reasons.
Hope this helps!