1
A
回答
2
D3不會對此有一個本地方法。但是,您可以在mousemove
事件與document.elementFromPoint()
結合d3.mouse()
:
var svg = d3.select("svg");
svg.on("mousemove", function() {
var mouse = d3.mouse(this);
var elem = document.elementFromPoint(mouse[0], mouse[1]);
console.log(elem.tagName)
})
<script src="https://d3js.org/d3.v4.min.js"></script>
<svg height="150" width="500">
<rect x="50" y="20" width="150" height="100" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9"/>
<ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow"/>
<ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white"/>
<circle cx="350" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
<line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:4"/>
</svg>
+0
作品完全接受你的回答,並且upvote謝謝你的出色答案 – commonSenseCode
0
也沒必要D3這個可以用js和/或jQuery的完成:
$("body").click(function(event) {
console.log("clicked: " + event.target.nodeName, event.target);
});
相關問題
- 1. 如何獲取當前在鼠標指針下的像素顏色
- 2. 獲取鼠標指針下的文本
- 3. 獲取鼠標指針下的文本
- 4. 在鼠標指針下獲取文字
- 5. 當鼠標移動時,Javascript計算鼠標指針下的元素數量
- 6. 獲取鼠標指針下的DIV列表(鼠標事件)
- 7. WPF獲取鼠標下的元素
- 8. 獲取相對於元素的鼠標指針的x和y位置
- 9. jQuery獲取鼠標當前懸停的子元素
- 10. 在鼠標下獲取對象
- 11. 查找相對於svg元素的鼠標指針位置
- 12. 嘗試對鼠標指針的多個元素進行評分
- 13. 獲取鼠標指針相對於某些div的座標
- 14. 如何獲得鼠標指針下的單元格(ListView)?
- 15. 指向對象表示元素的指針或指向提供的存儲元素的指針?
- 16. 在Javascript中,如何獲取鼠標指針所在div的當前id?
- 17. 獲取當前鼠標光標類型
- 18. 獲取雙指針指向的對象
- 19. jQuery:獲取當前元素後的立即下一個元素
- 20. 獲取當前元素
- 21. Safari瀏覽器:獲取鼠標指針下的單詞
- 22. 獲取父數組對象中當前元素的編號
- 23. 獲取對象中的當前元素Jquery
- 24. 獲取Raphael元素的當前變換狀態(作爲對象或字符串)
- 25. 如何獲取鼠標捕獲元素
- 26. 通過javascript獲取當前元素下方1個元素
- 27. 如何在鼠標指針WebBrowser控件下獲取文本?
- 28. C#webBrowser控件如何在鼠標指針下獲取數據
- 29. 在鼠標指針下獲取X和Y值
- 30. 對象指針賦值指針向量的元素
[在指定位置獲取元素 - 的JavaScript]的可能的複製(http://stackoverflow.com/questions/1259585/ get-element-at-specified-position-javascript) – altocumulus