完整代码
<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'; = 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>
参考