如何使SVG文本元素“点击通过”? [英] How to make an SVG text element "click-through-able"?

查看:78
本文介绍了如何使SVG文本元素“点击通过”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张带有SVG文本元素的地图来命名这些位置。我希望位置(形状)是可点击的,它们是,但因为文本元素位于它们之上,如果有人将鼠标悬停在文本元素上并单击,则没有任何反应,因为没有单击形状:文本元素是。如何点击文本元素,点击直通它到形状?

I have a map with SVG text elements to name the locations. I want the locations (shapes) to be clickable, and they are, but because the text elements are on top of them, if someone hovers over a text element and clicks, then nothing happens because the shape was not clicked : the text element was. How can I make it so that if the text element is clicked, the click goes "through" it and to the shape ?

推荐答案

为此,Mozilla引入了一个名为 pointer-events 的CSS属性。它最初仅限于SVG形状,但现在在现代浏览器中的大多数DOM元素上都受支持:

Mozilla introduced a CSS property for this purpose called pointer-events. It was originally limited to SVG shapes, but is now supported on most DOM elements in modern browsers:

span.label { pointer-events: none; }



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆