0
点赞
收藏
分享

微信扫一扫

js:获取鼠标点击位置,弹出提示框

js:获取鼠标点击位置,弹出提示框_5e

完整代码

<script>
// 监听鼠标点击事件
document.addEventListener('click', function(event){
console.log('mouseup');
let box = document.querySelector('#tip-box');

if(!box){
box = document.createElement('div');
box.classList.add('tip-box');
box.setAttribute('id', 'tip-box')
document.body.append(box);
}

box.innerHTML = 'Hello';
box.style.top = event.clientY + 'px';
box.style.left = event.clientX + 'px';
box.style.display = 'block';

})
</script>

<style>
.tip-box {
border: 1px solid #cfcfcf;
border-radius: 3px;
padding: 15px 22px;
position: fixed;
min-width: 300px;
max-width: 350px;
width: auto;
height: auto;
min-height: 100px;
background: #efefef;
display: none;
line-height: 1.5em;
}
</style>

参考
​​​JavaScript实现划词翻译​​


举报

相关推荐

0 条评论