From 549162047557b047eeeb45c967b550ed857545b9 Mon Sep 17 00:00:00 2001 From: utkuagus Date: Thu, 29 Aug 2024 16:37:35 +0300 Subject: [PATCH] fix disable other draggings --- drag-n-drop/script.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drag-n-drop/script.js b/drag-n-drop/script.js index abc8a6e..1ff2288 100644 --- a/drag-n-drop/script.js +++ b/drag-n-drop/script.js @@ -1,8 +1,9 @@ const fill = document.querySelector('.fill') const empties = document.querySelectorAll('.empty') +const body = document.body -fill.addEventListener('dragstart', dragStart) -fill.addEventListener('dragend', dragEnd) +body.addEventListener('dragstart', dragStart) +body.addEventListener('dragend', dragEnd) for(const empty of empties) { empty.addEventListener('dragover', dragOver) @@ -11,13 +12,17 @@ for(const empty of empties) { empty.addEventListener('drop', dragDrop) } -function dragStart() { - this.className += ' hold' - setTimeout(() => this.className = 'invisible', 0) +function dragStart(e) { + if(!e.target.classList.contains("fill")) { + e.preventDefault() + return + } + fill.className += ' hold' + setTimeout(() => fill.className = 'invisible', 0) } function dragEnd() { - this.className = 'fill' + fill.className = 'fill' } function dragOver(e) {