|
@@ -1,7 +1,7 @@
|
|
|
<script>
|
|
<script>
|
|
|
import { onMount, createEventDispatcher } from 'svelte';
|
|
import { onMount, createEventDispatcher } from 'svelte';
|
|
|
import { fly } from 'svelte/transition';
|
|
import { fly } from 'svelte/transition';
|
|
|
- import { throttle, stepNumberFun } from '../utils';
|
|
|
|
|
|
|
+ import { throttleWithRAF, debounce, stepNumberFun } from '../utils';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 当前值
|
|
* 当前值
|
|
@@ -167,8 +167,11 @@
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
const touchLineMove = e => {
|
|
const touchLineMove = e => {
|
|
|
- lineDom.setPointerCapture(e.pointerId);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (!lineDom.hasPointerCapture(e.pointerId)) {
|
|
|
|
|
+ lineDom.setPointerCapture(1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lineDom.setPointerCapture(e.pointerId);
|
|
|
|
|
+ }
|
|
|
if (disabled || readonly) {
|
|
if (disabled || readonly) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -212,12 +215,14 @@
|
|
|
dispatch('change', value); //触发事件 trigger event
|
|
dispatch('change', value); //触发事件 trigger event
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
- const touchLineEnd = () => {
|
|
|
|
|
|
|
+ const touchLineEnd = e => {
|
|
|
|
|
+ if (lineDom.hasPointerCapture(e.pointerId)) {
|
|
|
|
|
+ lineDom.releasePointerCapture(e.pointerId);
|
|
|
|
|
+ }
|
|
|
currentMove = 'none';
|
|
currentMove = 'none';
|
|
|
isDown = false;
|
|
isDown = false;
|
|
|
};
|
|
};
|
|
|
- const radiusObj = { none: ' rounded-none', base: ' rounded', xl: ' rounded-xl', full: ' rounded-full' };
|
|
|
|
|
- onMount(() => {
|
|
|
|
|
|
|
+ const handleResize = () => {
|
|
|
lineDomStartX = lineDom.getBoundingClientRect().left;
|
|
lineDomStartX = lineDom.getBoundingClientRect().left;
|
|
|
lineDomEndX = lineDom.getBoundingClientRect().right;
|
|
lineDomEndX = lineDom.getBoundingClientRect().right;
|
|
|
lineDomWidth = lineDom.getBoundingClientRect().width;
|
|
lineDomWidth = lineDom.getBoundingClientRect().width;
|
|
@@ -227,13 +232,18 @@
|
|
|
if (isRange) {
|
|
if (isRange) {
|
|
|
blockWidth = blockDom.getBoundingClientRect().width;
|
|
blockWidth = blockDom.getBoundingClientRect().width;
|
|
|
}
|
|
}
|
|
|
|
|
+ };
|
|
|
|
|
+ const radiusObj = { none: ' rounded-none', base: ' rounded', xl: ' rounded-xl', full: ' rounded-full' };
|
|
|
|
|
+ onMount(() => {
|
|
|
|
|
+ handleResize();
|
|
|
|
|
+ window.addEventListener('resize', debounce(handleResize, 200));
|
|
|
});
|
|
});
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<div class={`relative h-7${disabled ? ' opacity-50' : ''}`}>
|
|
<div class={`relative h-7${disabled ? ' opacity-50' : ''}`}>
|
|
|
<div
|
|
<div
|
|
|
on:pointerdown={touchLineStart}
|
|
on:pointerdown={touchLineStart}
|
|
|
- on:pointermove={throttle(touchLineMove)}
|
|
|
|
|
|
|
+ on:pointermove={throttleWithRAF(touchLineMove)}
|
|
|
on:pointerup={touchLineEnd}
|
|
on:pointerup={touchLineEnd}
|
|
|
class="absolute flex flex-col justify-center h-7 w-full touch-none cursor-move"
|
|
class="absolute flex flex-col justify-center h-7 w-full touch-none cursor-move"
|
|
|
bind:this={lineDom}
|
|
bind:this={lineDom}
|