From c86dd4c0d969ff679e9b1ad59f968bf2154b99bd Mon Sep 17 00:00:00 2001 From: Shahidul Alam Riyad Date: Tue, 27 Feb 2024 16:45:45 +0600 Subject: [PATCH 1/2] fix: absolute issue fixed --- src/components/AudioPlayer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/AudioPlayer.tsx b/src/components/AudioPlayer.tsx index 3ff59a9..f9893c5 100644 --- a/src/components/AudioPlayer.tsx +++ b/src/components/AudioPlayer.tsx @@ -205,7 +205,7 @@ export const AudioPlayer: React.FC = ({ if (direction === 'horizontal') { min = rangeBox.offsetLeft; max = min + rangeBox.offsetWidth; - if (event.clientX < min || event.clientX > max) return false; + if (event.clientX - rect.left < 0 || event.clientX - rect.right > 0) return false; } else { min = rect.top; max = min + rangeBox.offsetHeight; @@ -219,7 +219,7 @@ export const AudioPlayer: React.FC = ({ const rect = slider.getBoundingClientRect(); let K = 0; if (slider.dataset.direction === 'horizontal') { - const offsetX = event.clientX - slider.offsetLeft; + const offsetX = event.clientX - rect.left; const width = slider.clientWidth; K = offsetX / width; } else if (slider.dataset.direction === 'vertical') { From 69db2f3621ddf6245fb02c42f606abfe740e1e9f Mon Sep 17 00:00:00 2001 From: Shahidul Alam Riyad Date: Tue, 27 Feb 2024 16:54:12 +0600 Subject: [PATCH 2/2] refactor: code removed --- src/components/AudioPlayer.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/AudioPlayer.tsx b/src/components/AudioPlayer.tsx index f9893c5..018fce6 100644 --- a/src/components/AudioPlayer.tsx +++ b/src/components/AudioPlayer.tsx @@ -201,14 +201,11 @@ export const AudioPlayer: React.FC = ({ const rangeBox = getRangeBox(event, currentlyDragged.current); const rect = rangeBox.getBoundingClientRect(); const direction = rangeBox.dataset.direction; - let max, min; if (direction === 'horizontal') { - min = rangeBox.offsetLeft; - max = min + rangeBox.offsetWidth; if (event.clientX - rect.left < 0 || event.clientX - rect.right > 0) return false; } else { - min = rect.top; - max = min + rangeBox.offsetHeight; + const min = rect.top; + const max = min + rangeBox.offsetHeight; if (event.clientY < min || event.clientY > max) return false; } return true;