Skip to content

Commit

Permalink
prettier run
Browse files Browse the repository at this point in the history
  • Loading branch information
IshiniAvindya committed Nov 13, 2024
1 parent ce2f7db commit da1fc42
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/lib/components/Slider/Slider.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
function handleMouseup() {
dragging = false;
window.removeEventListener('mousemove', handleMousemove);
window.removeEventListener('mouseup', handleMouseup);
}
function handleMousemove(event: MouseEvent) {
if (!trackEl) return;
if (dragging) {
calcPosUpdateValue(trackEl,event.clientX);
calcPosUpdateValue(trackEl, event.clientX);
}
}
Expand All @@ -57,30 +58,35 @@
function handleTouchend() {
dragging = false;
window.removeEventListener('touchmove', handleTouchmove);
window.removeEventListener('touchend', handleTouchend);
}
function handleTouchmove(event: TouchEvent) {
if (!trackEl) return;
if (dragging) {
calcPosUpdateValue(trackEl, event.touches[0].clientX);
}
}
}
function calcPosUpdateValue(trackEl: HTMLDivElement, clientX: number){
function calcPosUpdateValue(trackEl: HTMLDivElement, clientX: number) {
const rect = trackEl.getBoundingClientRect();
const x = clientX - rect.left;
const width = rect.width;
const newValue = min + (x / width) * (max - min);
value = toStep(newValue);
dispatch('change', value);
const x = clientX - rect.left;
const width = rect.width;
const newValue = min + (x / width) * (max - min);
value = toStep(newValue);
dispatch('change', value);
}
</script>

<div class="slider">
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="track" bind:this={trackEl} class:dragging onmousedown={handleMousedown} ontouchstart={handleTouchstart}>
<div
class="track"
bind:this={trackEl}
class:dragging
onmousedown={handleMousedown}
ontouchstart={handleTouchstart}
>
<div class="progress" style="width: {progress}%"></div>
<button class="handle" style="left: {progress}%">
<span class="tip">
Expand Down

0 comments on commit da1fc42

Please sign in to comment.