console
const box = document.getElementById('box')
box.onmousemove = function (e) {
box.innerHTML = `${e.clientX}, ${e.clientY}`
}
function throttle(func, delay) {
let run = true;
return function () {
if (!run) {
return
}
run = false
setTimeout(() => {
func.apply(this, arguments)
run = true
console.log(this);
}, delay)
}
}
box.onmousemove = throttle(function (e) {
box.innerHTML = `${e.clientX}, ${e.clientY}`
}, 500)
<style>
#box {
width: 1000px;
height: 500px;
background: #ccc;
font-size: 40px;
text-align: center;
line-height: 500px;
}
</style>
<div id="box"></div>
body{
display:flex;
flex-direction:column;
justify-content: center;
align-items: center;
height: 100vh;
}