SVG:获取点击的元素
SVG: Get clicked element
如何获取 SVG 中点击的具体元素?
this.svgEl = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var s = Snap(this.svgEl);
var svgFromApi = (new DOMParser()).parseFromString("svg image from API", "image/svg+xml");
s.clear();
s.append(svgFromApi.documentElement);
this.divElementRef.nativeElement.appendChild(this.svgEl);
this.svgElement.onclick = ()=> {
//Need to get on which element inside SVG it was clicked.
}
试试这个
this.svgEl.onclick = (event) => {
// event.target should contain the element that was clicked on
}
如何获取 SVG 中点击的具体元素?
this.svgEl = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var s = Snap(this.svgEl);
var svgFromApi = (new DOMParser()).parseFromString("svg image from API", "image/svg+xml");
s.clear();
s.append(svgFromApi.documentElement);
this.divElementRef.nativeElement.appendChild(this.svgEl);
this.svgElement.onclick = ()=> {
//Need to get on which element inside SVG it was clicked.
}
试试这个
this.svgEl.onclick = (event) => {
// event.target should contain the element that was clicked on
}