pointer-events
Базовая поддержка Широко доступно
Эта функция хорошо зарекомендовала себя и работает на многих устройствах и в разных версиях браузеров. Она доступна во всех браузерах с июля 2015 года.
Атрибут pointer-events — это атрибут представления, который позволяет определить, может ли элемент быть целью события мыши и когда это возможно.
Примечание: у pointer-events как атрибута представления также есть соответствующее свойство CSS: pointer-events. Если заданы оба варианта, приоритет имеет свойство CSS.
Этот атрибут можно использовать со следующими SVG-элементами:
Пример
<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg"> <!-- The circle will always intercept the mouse event. To change the color of the rect underneath you have to click outside the circle --> <rect x="0" y="0" height="10" width="10" fill="black" /> <circle cx="5" cy="5" r="4" fill="white" pointer-events="visiblePainted" /> <!-- The circle below will never catch a mouse event. The rect underneath will change color whether you are clicking on the circle or the rect itself --> <rect x="10" y="0" height="10" width="10" fill="black" /> <circle cx="15" cy="5" r="4" fill="white" pointer-events="none" /> </svg>
window.addEventListener("mouseup", (e) => {
// Let's pick a random color between #000000 and #FFFFFF
const color = Math.round(Math.random() * 0xffffff);
// Let's format the color to fit CSS requirements
const fill = `#${color.toString(16).padStart(6, "0")}`;
// Let's apply our color in the
// element we actually clicked on
e.target.style.fill = fill;
});
Примечания по использованию
| Значение | bounding-box | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | none |
|---|---|
| Значение по умолчанию | visiblePainted |
| Анимируемое | Да |
Подробное описание всех возможных значений см. в документации по CSS-свойству pointer-events.
Спецификации
Совместимость с браузерами
| Настольные компьютеры | Мобильные устройства | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome для Android | Firefox для Android | Opera для Android | Safari для iOS | Samsung Internet | WebView для Android | WebView для iOS | |
pointer-events |
1 | 12 | 1.5 | 9 | 4 | 18 | 4 | 14 | 3.2 | 1.0 | 3 | 3.2 |
См. также
- свойство CSS
pointer-events
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/pointer-events