Skip to content

Files

Latest commit

069bb59 · Mar 20, 2021

History

History
25 lines (20 loc) · 608 Bytes

useSlider.md

File metadata and controls

25 lines (20 loc) · 608 Bytes

useSlider

Vue UI hook that provides slide behavior over any HTML element. Supports both mouse and touch events.

Usage

import {useSlider, useRef} from 'vue-next-use';

const Demo = () => {
  const ref = useRef(null);
  const {isSliding, value, pos, length} = useSlider(ref);

  return (
    <div>
      <div ref={ref} style={{ position: 'relative' }}>
        <p style={{ textAlign: 'center', color: isSliding ? 'red' : 'green' }}>
          {Math.round(state.value * 100)}%
        </p>
        <div style={{ position: 'absolute', left: pos }}>🎚</div>
      </div>
    </div>
  );
};