console
let container = document.querySelector('.container')
container.addEventListener('click', _debounce((e) => {
if (e.target.nodeName === 'DIV') {
console.log(e.target.innerText)
}
}))
function _throttle (fn, interval = 500) {
let canrun = true
return function () {
if (!canrun) return
canrun = false
setTimeout(() => {
console.log(this === container)
fn.apply(this, arguments)
canrun = true
}, interval)
}
}
function _debounce (fn, interval=2000) {
let time = null
return function () {
window.clearTimeout(time)
time = setTimeout(() => {
fn.apply(this, arguments)
}, interval)
}
}
<div class="container">
<p>66666</p>
<div class="a">11</div>22
<div class="b">33</div>44
<div class="c">55</div>66
</div>
<div class="next"></div>
.container {
width: 600px;
background: rgba(0,0,0,.2);
display: inline-block;
}
.container::after {
}
.a {
width: 50px;
height:100px;
background: #000;
float: left;
display: inline-block;
}
.b {
width: 80px;
height:100px;
background: #666;
float: left;
display:inline-block;
}
.c {
width: 100px;
height: 100px;
background: red;
float: left;
display:inline-block;
}
.next {
widht: 50px;
height: 50px;
background: blue;
}