前端文字实现拼音标注

7 篇文章 0 订阅

示例地址

  • https://github.com/superBiuBiuMan/duyi_study

使用ruby标签

  • 使用ruby标签进行标注
<ruby><rt>hàn</rt>
</ruby>

  • 当遇到不兼容此标签的时候,可以添加一个rp标签,正确情况下是不显示rp标签的
<ruby><rp>(</rp>
    <rt>hàn</rt>
    <rp>)</rp>
</ruby>

使用拼音库

  • https://pinyin.js.org/

  • https://www.npmjs.com/package/pinyin

  • 安装

npm install pinyin@alpha --save
  • 使用看官网
  • 示例
import pinyin from "pinyin/lib/pinyin-web";
pinyin('你')
  • 效果

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在前端实现箭头指向图片位置并进行标注,可以使用以下步骤: 1. 在 HTML 中添加图片和标注元素。可以使用 `<img>` 标签添加图片,使用 `<div>` 或其他元素添加标注。 2. 在 CSS 样式中,设置图片和标注元素的样式和位置。可以使用 `position` 属性对它们进行定位。 3. 使用 JavaScript 监听鼠标事件,当鼠标点击图片时,显示对应的标注元素,并根据鼠标位置动态计算标注元素的位置和内容。 4. 根据鼠标位置动态计算箭头元素的位置,并设置箭头的朝向,使其指向对应的图片元素。 代码示例: HTML: ```html <div class="container"> <img src="example.jpg" class="image"> <div class="annotation" id="annotation1"> <div class="arrow"></div> <div class="content">这是标注内容</div> </div> </div> ``` CSS: ```css .container { position: relative; } .image { position: relative; width: 200px; height: 150px; } .annotation { position: absolute; display: none; } .arrow { position: absolute; width: 20px; height: 20px; background-color: black; transform: rotate(45deg); } .content { position: absolute; top: 0; left: 0; padding: 10px; background-color: white; border: 1px solid black; } ``` JavaScript: ```javascript const image = document.querySelector('.image'); const annotation = document.querySelector('.annotation'); const arrow = annotation.querySelector('.arrow'); const content = annotation.querySelector('.content'); image.addEventListener('click', event => { const mouseX = event.clientX; const mouseY = event.clientY; const imageRect = image.getBoundingClientRect(); const arrowRect = arrow.getBoundingClientRect(); const arrowTop = mouseY - arrowRect.height / 2; const arrowLeft = mouseX - arrowRect.width; arrow.style.top = arrowTop + 'px'; arrow.style.left = arrowLeft + 'px'; const contentTop = arrowTop + arrowRect.height / 2; const contentLeft = arrowLeft - content.getBoundingClientRect().width; content.style.top = contentTop + 'px'; content.style.left = contentLeft + 'px'; content.innerText = '这是标注内容'; annotation.style.display = 'block'; }); document.addEventListener('click', event => { if (event.target !== image && event.target !== content) { annotation.style.display = 'none'; } }); ``` 在上述代码中,首先获取图片元素和标注元素,并监听图片的 `click` 事件。当鼠标点击图片时,显示对应的标注元素,并根据鼠标位置动态计算标注元素的位置和内容。同时,根据鼠标位置动态计算箭头元素的位置,并设置箭头的朝向,使其指向对应的图片元素。当用户点击页面其他区域时,隐藏标注元素。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未成年梦想

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值