当前位置:网站首页>Dynamic addition of prompt information for successful operation
Dynamic addition of prompt information for successful operation
2022-06-21 07:19:00 【Glow rabbit】
When the current element is clicked , Prompt for successful addition tips. Often in calculation tips The location is troublesome , Such work has been completed in work practice , Share the record .
ele.addEventListener('click', function(e){
var targetDom = e.srcElement||e.target;
addTooltip(e, targetDom, 'CopySuccessfully');
}, false);
function addTooltip(e, targetDom, tipsText) {
if (!e || !targetDom) {
return;
}
const tooltipDom = document.querySelector(
`[data-insert-tooltip-text="${tipsText}]"`
);
if (tooltipDom) {
tooltipDom.remove();
}
const { clientX, clientY } = e;
const { top, left, width, height } = targetDom.getBoundingClientRect();
const clientWidth = document.body.clientWidth;
const tooltipMargin = 4;
const tooltipHeight = 32;
const tooltipWidth = 170;
const position = {
top: parseInt(top - tooltipMargin - tooltipHeight),
bottom: parseInt(top + height + tooltipMargin),
left:
clientX > parseInt(tooltipWidth / 2)
? parseInt(clientX - tooltipWidth / 2)
: clientX,
right: parseInt(clientX - tooltipWidth)
};
const wrap = document.createElement('div');
console.log(position);
wrap.innerHTML = `<div data-insert-tooltip="true" data-insert-tooltip-text="${tipsText}" style="
position: fixed;
border-radius: 3px;
background-color: #212121;
padding: 6px 16px;
display: flex;
align-items: center;
font-size: 13px;
color: #fff;
font-weight: 400;
white-space: nowrap;
top: ${position.top > 0 ? position.top : position.bottom}px;
left: ${
position.left > 0 && position.left < clientWidth
? position.left
: position.right
}px;
z-index: 2147483647;
">
<svg
style="width: 16px; height: 16px; fill: #fff; margin-right: 8px;"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg">
<path d="M512 0C229.696 0 0 229.696 0 512s229.696 512 512 512 512-229.696 512-512-229.696-512-512-512z m0 960c-246.976 0-448-201.024-448-448s201.024-448 448-448 448 201.024 448 448-201.024 448-448 448z" />
<path d="M828.544 349.696L433.92 744.32 195.456 503.872a40.64 40.64 0 1 1 57.472-57.472l180.992 182.4 337.152-337.152a40.64 40.64 0 1 1 57.472 57.472v0.576z" />
</svg>
<span>${tipsText}</span>
</div>`;
const tooltip = wrap.firstChild;
document.body.appendChild(tooltip);
setTimeout(function() {
tooltip && tooltip.remove();
}, 1500);
}
边栏推荐
- 【正则表达式每日一技】逃逸正则表达式中具有特殊含义的字符
- Use the loupe cell browser to view the results of 10x single cell transcriptome analysis
- 布隆过滤器
- 微信小程序_5,全局配置
- 微信小程序_3,WXML模板语法
- Necessary free artifact for remote assistance todesk remote control software (defense, remote, debugging, office) necessary remote tools
- @nonnull annotation of Lombok
- Wechat applet_ 4. Wxss template style
- Yield guild games and Walken reach cooperation
- Microphone loading animation
猜你喜欢
![[transfer] liurun: don't discuss business with people without logic](/img/e7/7881a9f02c7773f92702f6b0232125.png)
[transfer] liurun: don't discuss business with people without logic

The left column of WordPress implementation shows the article directory

win10上vs2017配置Eigen3开发环境

EasyExcel-简介-01

Eigen common operations

根因解析 | Kubernetes Pod状态异常九大场景盘点

微信小程序_5,全局配置

【毕业季-进击的技术er】:即将大四在校生的技术分享,未来共勉

一文搞懂this指向

Matplotlib subgraph beautification
随机推荐
flutter jpush
2022年大学英语六级6月翻译
Two ideas of I2C driver implementation (I2C dev.c and I2C core.c)
EasyExcel-排除展示字段-02
[mapbox] Basics
thinkphp的这些扩展插架你都知道吗?
2022年6月13日面试被问到面试题目
Introduction to missing data filling dataset (1) -- Introduction to multiple datasets and dataset preprocessing (beast, covertype, credit, EEG, iris and letter)
【GNN】GNN图神经网络工具箱的应用和matlab仿真
Minesweeping - C language - Advanced (recursive automatic expansion + chess mark)
IDM mobile terminal function upgrade description
C language conditional operator?: The only ternary operator
Best practice | how to use Tencent cloud micro build to develop enterprise portal applications from 0 to 1
June translation of CET-6 in 2022
Introduction to exceptions
根因解析 | Kubernetes Pod状态异常九大场景盘点
Four necessary steps for building a digital factory
【3】 AI studio project details - single machine multi machine training distributed training - Parl
海思系列量产硬件调试记录
Feature scaling for machine learning