D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
romsson
Full window
Github gist
detect olverapped SVG elements intersections
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // https://stackoverflow.com/questions/16799116/handling-mouse-events-in-overlapping-svg-layers function passThru(d) { console.log("selected color: ", d3.select(this).style("fill")) var e = d3.event; var prev = this.style.pointerEvents; this.style.pointerEvents = 'none'; var el = document.elementFromPoint(d3.event.x, d3.event.y); var e2 = document.createEvent('MouseEvent'); e2.initMouseEvent(e.type,e.bubbles,e.cancelable,e.view, e.detail,e.screenX,e.screenY,e.clientX,e.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,e.button,e.relatedTarget); el.dispatchEvent(e2); this.style.pointerEvents = prev; } var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) svg.append("circle") .attr("cy", 150) .attr("cx", 150) .attr("r", 150) .style("fill", "red") .style("opacity", .2) .on("click", passThru); svg.append("circle") .attr("cy", 200) .attr("cx", 350) .attr("r", 150) .style("fill", "green") .style("opacity", .2) .on("click", passThru); svg.append("circle") .attr("cy", 300) .attr("cx", 250) .attr("r", 150) .style("fill", "yellow") .style("opacity", .2) .on("click", passThru); </script> </body>
https://d3js.org/d3.v4.min.js