用jquery canvas元素显示隐藏的div

时间:2014-11-30 14:18:25

标签: javascript jquery html canvas

我有HTML画布,上面画有圆圈。我能够在每个圆圈上显示一个点击事件以显示警报,但我希望每个人在点击时显示隐藏的div。我尝试了所有我能想到的东西,但它不起作用。请帮忙!

HTML:

<div id="1" class="toggle" style="display:none"></div>
<div id="2" class="toggle" style="display:none"></div>
<div id="3" class="toggle" style="display:none"></div>
<div id="4" class="toggle" style="display:none"></div>

JS :(摘录)

    var drawCircle = function (context, x, y, fillcolor, radius, linewidth, strokestyle, fontcolor,    textalign, fonttype, filltext, div, circles) {
    draw(context, x, y, fillcolor, radius, linewidth, strokestyle, fontcolor, textalign, fonttype, filltext);
    var circle = new Circle(x, y, radius);
    circles.push(circle);  
};

drawCircle(context, 300, canvas.height / 2, "green", 40, 5, "#003300", "white", "center", "bold 32px Arial", "1", "#1", circles);
drawCircle(context, 600, canvas.height / 3, "blue", 50, 5, "#003300", "white", "center", "bold 32px Arial", "2", "#2", circles);

$('#mapCanvas').click(function (e) {
    var clickedX = e.pageX - this.offsetLeft;
    var clickedY = e.pageY - this.offsetTop;

    for (var i = 0; i < circles.length; i++) {
        if (clickedX < circles[i].right && clickedX > circles[i].left && clickedY > circles[i].top && clickedY < circles[i].bottom) {
            /*alert ('clicked number ' + (i + 1));*/
            $(this).attr("div").show;
        }
    }
});

提前致谢!

1 个答案:

答案 0 :(得分:1)

如果'i'是点击的圈数,从0开始,

这应该有效。

$('#'+(i+1)).show();