将 jquery 事件传递到后面的层或使内半径透明

发布于 2024-12-08 13:46:18 字数 583 浏览 1 评论 0原文

我正在尝试在另一个饼图之上制作一个饼图(见下文),并使用 flot jquery 库。

http://cadmiumconsulting.com/carlsberg/screenshot_01.jpg

我已经设法得到了图表看起来不错,但想在外部饼图上使用鼠标事件。

我的问题是:

如果我先绘制外部图表,而内部图表位于“顶部”,则鼠标事件仅在内层上起作用。

另一方面,如果我先绘制内部图表,然后在“顶部”添加具有内半径的外部图表,则内半径在 Internet Explorer 8 中不起作用,并在内部图表的顶部显示实心圆。

关于如何将事件从一层传递到另一层或强制内半径的透明度有什么想法吗?

任何帮助表示赞赏。

更新 - “globalCompositeOperation”似乎存在问题,这将允许透明度。它包含在 html5 中,但不包含在 excanvas 对象中,这是在 IE8 中复制 canvas 对象的一种 hack。

I'm trying to make a pie chart on top of another pie chart (see below) and am using the flot jquery library.

http://cadmiumconsulting.com/carlsberg/screenshot_01.jpg

I have managed to get the diagram looking right but would like to use mouse events on the outer pie chart.

My problem is:

If I draw the outer chart first with the inner one 'on top', mouse events only work on the inner layer.

If on the other hand I draw the inner chart first and add the outer chart 'on top' with an inner radius, the inner radius doesn't work in internet explorer 8 and displays a solid circle over the top of the inner chart.

Any ideas on how to pass events from one layer to the other or force the transparency of the inner radius?

Any help appreciated.

UPDATE - There seems to be an issue with 'globalCompositeOperation' which would allow the transparency. It's included in html5 but not in the excanvas object which is a hack to replicate the canvas object in IE8.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难得心□动 2024-12-15 13:46:18

事件不断移动,因此您应该能够在后台定位图表。我做了这个
简单指南,解释事件如何传播以及如何在 jQuery 中停止它们:

首先,我们创建测试 DOM

<div><br/>
    <a class="a1">Im plain simple</a><br/><br/>
    <a class="a2" href="http://google.com">I prevent my own other events</a><br/><br/>
    <a class="a3">I stop other event</a><br/><br/>
    <a class="a4" href="http://google.com">Im shitty</a><br/><br/>
    <a class="a5" href="http://google.com">Im shitty too</a><br/><br/>
</div>

样式:

div {background:red;}
a {color:white;}
a.a1 {background:yellow;color:black;}
a.a2 {background:green;}
a.a3 {background:blue;}
a.a4 {background:orange;}

jQuery:

我们将 click 事件绑定到 div 来测试我们的传播

$("div").bind("click", function(event) {
    alert("div clicked");
});

Click 事件最终传播到 div

$("a.a1").bind("click", function(event) {
    alert("a.a1 clicked");
});

使用 event .preventDefault() 阻止所有 $("a.a2") 其他绑定点击事件。

$("a.a2").bind("click", function(event) {
    event.preventDefault();
    alert("a.a2 clicked\n\nactually I was supposed to go to http://google.com");
});

使用 event.stopPropagation() 可以防止点击事件传播,并且它永远不会触发 div 上的边界事件

$("a.a3").bind("click", function(event) {
    event.stopPropagation();
    alert("a.a3 clicked");
});

。现在我们将其结合使用。

$("a.a4").bind("click", function(event) {
    event.preventDefault();
    event.stopPropagation();
    alert("a.a4 clicked\n\nI was also supposed to go to http://google.com");
});

另一种方法是返回 false;最后,这也适用于现场活动。

$("a.a5").bind("click", function(event) {
    alert("a.a5 clicked\n\nI was also supposed to go to http://google.com");
    return false;
});

希望这有帮助。

如果您需要更多帮助,请发布一些代码(在其中绑定事件)或图表示例

Events traveling so you should be able to target the chart in the background. I have made this
simple guide that explains how events travel and how to stop them in jQuery:

First we create our test DOM

<div><br/>
    <a class="a1">Im plain simple</a><br/><br/>
    <a class="a2" href="http://google.com">I prevent my own other events</a><br/><br/>
    <a class="a3">I stop other event</a><br/><br/>
    <a class="a4" href="http://google.com">Im shitty</a><br/><br/>
    <a class="a5" href="http://google.com">Im shitty too</a><br/><br/>
</div>

Styling:

div {background:red;}
a {color:white;}
a.a1 {background:yellow;color:black;}
a.a2 {background:green;}
a.a3 {background:blue;}
a.a4 {background:orange;}

jQuery:

We bind a click event to the div to test our travelings

$("div").bind("click", function(event) {
    alert("div clicked");
});

Click event that travels to the div eventually

$("a.a1").bind("click", function(event) {
    alert("a.a1 clicked");
});

Using event.preventDefault() prevents all $("a.a2") other bound click events.

$("a.a2").bind("click", function(event) {
    event.preventDefault();
    alert("a.a2 clicked\n\nactually I was supposed to go to http://google.com");
});

Using event.stopPropagation() prevents the click event from traveling and it never triggers the bounds events on our div

$("a.a3").bind("click", function(event) {
    event.stopPropagation();
    alert("a.a3 clicked");
});

Now we use there to in combination.

$("a.a4").bind("click", function(event) {
    event.preventDefault();
    event.stopPropagation();
    alert("a.a4 clicked\n\nI was also supposed to go to http://google.com");
});

And another way is to return false; in the end this also works for live events.

$("a.a5").bind("click", function(event) {
    alert("a.a5 clicked\n\nI was also supposed to go to http://google.com");
    return false;
});

Hopes this helps.

If you want more help please post some code (where you bind your events) or an example to your charts

岁月染过的梦 2024-12-15 13:46:18

“globalCompositeOperation”似乎存在允许透明度的问题。它包含在 html5 中,但不包含在 excanvas 对象中,这是在 IE8 中复制 canvas 对象的一种 hack。决定放弃我正在构建的示例并使用画布操作自己创建图表。

There seems to be an issue with 'globalCompositeOperation' which would allow the transparency. It's included in html5 but not in the excanvas object which is a hack to replicate the canvas object in IE8. Decided to abandon flot for the example I'm building and create the charts myself using canvas operations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文