我已經(jīng)努力解決這個(gè)問(wèn)題好幾天了。頁(yè)面底部有一個(gè)帶有可點(diǎn)擊項(xiàng)目的滑塊。我把滑塊做成了可拖動(dòng)的。但問(wèn)題是,當(dāng)拖動(dòng)停止時(shí),鼠標(biāo)按下事件發(fā)生的項(xiàng)目上也會(huì)發(fā)生單擊動(dòng)作。我嘗試過(guò)在拖動(dòng)開(kāi)始后在內(nèi)部項(xiàng)目中添加“pointer-ve nts: none ”,但在這種情況下draggint根本不起作用。我該如何解決這個(gè)問(wèn)題呢?
https://du olutions-wondrous-site . webflow . io/strau do-branding-naming
webflow的只讀鏈接:https://preview . webflow . com/preview/du olutions-wondours-site?utm _ medium = preview _ link & amputm _ source =設(shè)計(jì)師& ampUTM _ content = duo lutions-wonders-site & amp;preview = 9e 5312190 b 70 be 978 f 65b 8da 04 FB cefc & amp;pageId = 6377 be 41955 Fe 23 FB 7 C4 BF 33 & amp;工作流=預(yù)覽
<script>
let isDown = false;
let startX;
let scrollLeft;
const slider = document.querySelector('.items');
const end = () => {
isDown = false;
slider.classList.remove('active');
}
const start = (e) => {
isDown = true;
slider.classList.add('active');
startX = e.pageX || e.touches[0].pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
}
const move = (e) => {
if(!isDown) return;
e.preventDefault();
const x = e.pageX || e.touches[0].pageX - slider.offsetLeft;
const dist = (x - startX);
slider.scrollLeft = scrollLeft - dist;
}
(() => {
slider.addEventListener('mousedown', start);
slider.addEventListener('touchstart', start);
slider.addEventListener('mousemove', move);
slider.addEventListener('touchmove', move);
slider.addEventListener('mouseleave', end);
slider.addEventListener('mouseup', end);
slider.addEventListener('touchend', end);
})();
</script>
沒(méi)有到工作沙箱的鏈接,所以我不能確定它是否有幫助,但我注意到你沒(méi)有使用Event.stopPropagation()。這應(yīng)該會(huì)停止當(dāng)前事件的傳播。你可以在這里了解更多