内嵌文本的可访问性 <svg>

问题描述 投票:0回答:1
html accessibility wai-aria wai
1个回答
0
投票

不用JS复制文本确实不简单。

此标记在屏幕阅读器上适合您吗?

document.addEventListener('copy', (event) => {
  const selection = window.getSelection().toString();
  if (selection.includes("Deadpool") && selection.includes("Wolverine")) {
    event.clipboardData.setData('text/plain', "Deadpool and Wolverine");
    event.preventDefault();
  }
});
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
<h2>
  <span class="sr-only">Deadpool and Wolverine</span> Deadpool
  <svg width="53" height="64" class="inline" aria-hidden="true">
        <use href="#oleo-ampersand"></use>
    </svg> Wolverine:
  <br> A StackOverflow Example
</h2>

© www.soinside.com 2019 - 2024. All rights reserved.