Snap.getElementByPoint(x, y)

返回给定点最上面一个元素。


参数
  • x 数值。点的x位置。
  • y 数值。点的y位置。

返回值

对象。Snap元素对象。


使用
<svg id="svg" width="100" height="100"></svg>
var svg = Snap("#svg");
var c1 = svg.paper.circle(50,50,40).attr({
    fill: "red" 
}), c2 = svg.paper.circle(100,50,40).attr({
    fill: "green"
}), c3 = svg.paper.circle(150,50,40).attr({
    fill: "yellow"
});

Snap.click(function(e,x,y){
    c1.attr({strokeWidth:0});
    c2.attr({strokeWidth:0});
    c3.attr({strokeWidth:0});
    var c_in = Snap.getElementByPoint(x, y);
    c_in.attr({
            stroke: "blue",
            strokeWidth: 5
    });
});

用单击坐标获取元素,添加描边