当前位置: 首页 > news >正文

vue3 v-html绑定数据,点击sub实现popover效果

<p v-html="handleContent(article)"></p>
const handleContent = (article) =>{...content = content.repalce('xxx', '<sup class="sup" onclick="popover('sup-'+id, info)">'+infoName+'</sup>'); // 给sup一个唯一ID
}// 定时器
const timer;const popover = (parentId, msg) =>{// 创建显示divconst duration = 1000;const m = document.createElement('div');m.innerHTML = msg;clearTimeout(timer);let pop = document.getElementsByClassName('pop');if (pop.length > 0) {for (let i = 0; i < pop.length; i += 1) {pop[i].parentNode.removeChild(toast[i]);}}m.classList.add('pop-sub', 'pop');document.getElementById(fatherId).appendChild(m);// 定时清除setTimeout(() => {const d = 1;m.style.transition = `-webkit-transform ${d}s ease-in, opacity ${d}s ease-in`;m.style.opacity = '0';timer = setTimeout(() => {pop = document.getElementsByClassName('pop');if (pop.length > 0) {for (let i = 0; i < pop.length; i += 1) {pop[i].parentNode.removeChild(pop[i]);}}}, d * 1000);}, duration);
}
sup.sup{position: relative;
}
.pop{position: absolute;left: 50%;bottom: 24px;width: 300px;line-height: 22px;font-size: 12px;color: #fff;background: #333;border-radius: 6px;padding: 6px 6px;transform: translate(-50%, 0);&::after {position: absolute;bottom: -8px;left: 50%;border-top: 8px solid #333;border-right: 8px solid transparent;border-left: 8px solid transparent;content: '';transform: translate(-50%, 0);}
}

效果如下

http://www.lryc.cn/news/606181.html

相关文章:

  • STM32 USB 设备中间件 tinyusb
  • 超宽带测距+测角+无线通信一体化模组:智能门锁、智能遥控器、AR头戴、智能穿戴
  • 融媒体中心网络安全应急预案(通用技术框架)
  • Vmvare虚拟机的网络不可达问题
  • Spring Boot 异常处理:从全局捕获到优化用户体验!
  • 爱心烟花浪漫立方体轮播图 - 用代码表达爱意
  • 为Github Copilot创建自定义指令/说明/注意事项
  • 决策树实现回归任务
  • 基于Spring Boot实现中医医学处方管理实践
  • 【Agent,智能,workflow】
  • 【RH134 问答题】第 13 章 运行容器
  • uvicorn 启动重复加载 多次加载
  • [12月考试] B
  • Python 数据科学与可视化工具箱 (一) - 数组属性:`shape`, `dtype`, `ndim`, `size`
  • day28_2025-07-31
  • Valgrind终极指南:深入内存安全与性能瓶颈检测
  • 进程控制:从创建到终结的完整指南
  • 解决音视频开发中 因mp4中断 无法播放的问题
  • [特殊字符] 数据可视化结合 three.js:让 3D 呈现更精准,3 个优化经验谈
  • 前端框架Vue3(三)——路由和pinia
  • RabbitMQ安装与介绍
  • Disruptor高性能基石:Sequence并发优化解析
  • 去重、top_n()、pull()、格式化
  • 数据结构第4问:什么是栈?
  • BR/EDR PHY帧结构及其具体内容
  • 51c自动驾驶~合集12
  • python基础语法3,组合数据类型(简单易上手的python语法教学)(课后习题)
  • 从0到1了解热部署
  • 一天两道力扣(7)
  • 力扣 hot100 Day61