【发布时间】:2020-01-26 11:25:35
【问题描述】:
我试图在点击后获取点击的手风琴标题的绝对位置。
问题是,Bootstrap 的手风琴折叠运动和我的 jquery 几乎是在同一个时刻触发的。发生的事情是我的 jquery 在折叠手风琴之前获得了偏移量。
折叠后,点击后标题可以有另一个offsetTop。
有没有办法在折叠后给我的 jquery 加注星标,或者稍等片刻让手风琴折叠,然后请求offsetTop?
const handle = document.querySelector('#handle');
const headers = document.querySelectorAll('.accordion')
.forEach(el => {
el.addEventListener('mouseover', e => {
handle.style.top = `${e.currentTarget.offsetTop}px`;
});
});
如您在示例中看到的,如果您先打开第一部分,然后再打开第二部分,点会向下移动很远。
如果您再次单击第二部分,它会移动到正确的位置
【问题讨论】:
标签: javascript jquery html